check for dead dfs links

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Ondrej Zilinec Ondrej Zilinec 2 years, 1 month ago.

  • Author
    Posts
  • #20320
    Profile photo of tw h
    tw h
    Participant

    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 \\domain.com\home\userb \\server\home1$\userb

    "userb" leaves the organisation,

     del \\server\home1$\userb /s
    

    The link \\domain.com\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 "\\domain.com\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 \\domain.com\home /batch[/blockquote], and you receive all dfs-folders. I could still use this, but can I use powershell to find the same info ?
    [hr]
    This is also an option, but very,very slow if you have a lot of data:

    Get-ChildItem -Attributes Reparsepoint -Directory -Path "\\domain.com\home" -Recurse

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

    dfscmd /map  \\domain.com\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
    Profile photo of Ondrej Zilinec
    Ondrej Zilinec
    Participant

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

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

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

You must be logged in to reply to this topic.