check for dead dfs links

This topic contains 1 reply, has 2 voices, and was last updated by  Ondrej Zilinec 3 years, 4 months ago.

  • Author
  • #20320

    tw h

    I am trying to write a program to check all links in a dfs-namespace. Sometimes those folders are deleted, but the link is still there. Eg.

    mkdir \home1\userb
    dfscmd /map \\\home\userb \\server\home1$\userb

    "userb" leaves the organisation,

     del \\server\home1$\userb /s

    The link \\\home\userb is still there....pointing to nowhere.
    This example is with users, but also applies to data or groupdata, or whatever.

    So I want to enumerate, and check all folders/links if they point to existing targets.
    get-dfsnroot to find the dfsn-root object. Then something like "EnumerateFolders", but

    get-dfsnroot "\\\home" | gm

    gives nothing usefull.
    get-dfsnfolder could do the trick, but you need a path to the folder (which I do not have yet).
    A long time ago, in W2008R2 time, one could do [blockquote]dfscmd /view \\\home /batch[/blockquote], and you receive all dfs-folders. I could still use this, but can I use powershell to find the same info ?
    This is also an option, but very,very slow if you have a lot of data:

    Get-ChildItem -Attributes Reparsepoint -Directory -Path "\\\home" -Recurse

    There is a need for recursion because it is possible to have directories of links in a DFS namespace, eg.

    dfscmd /map  \\\home\special\userX \\server\home2$\userX

    Under the home, there is now a directory "special", with just one dfs-link in it. If it is enumerated with get-childitem without recursion, it does not have the Resparse attribute, and the link in it, is not found.

    How can I efficiently enumerate ALL dfs-links in a DFS namespace ? dfscmd can do it, why can't powershel do it ?

  • #20337

    Ondrej Zilinec

    I just made really quick one script, which would do recursive look into DFS structure.

    $StartRoot = "\\\data\*"
    Function Deeper($Root)
        $DFSRoot = Get-DfsnFolder -Path $Root
        Foreach ($Folder in $DFSRoot)
            $temp = $Folder.Path
            $temp += "\*"
            write-host $Folder.Path - $Folder.State

    There has to be only some check of "State" of the link.

You must be logged in to reply to this topic.