check for dead dfs links

Welcome Forums General PowerShell Q&A check for dead dfs links

This topic contains 1 reply, has 2 voices, and was last updated by

 
Participant
4 years, 5 months ago.

  • Author
    Posts
  • #20320

    Participant
    Points: 0
    Rank: Member

    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

    dfscmd /view \\domain.com\home /batch

    , 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 "\\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

    Participant
    Points: 0
    Rank: Member

    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.

The topic ‘check for dead dfs links’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort