Script to Get Currently Setup DFS Details

Let’s say you want to get a preview of how DFS is setup before you start making any changes. Following script will output the current dfs setup.

This script first imports the DFS module using Import-Module DFSR. It then uses the Get-DfsnServerConfiguration cmdlet to get a list of all DFS Namespace servers in the domain.

For each namespace server, the script uses the Get-DfsnRoot cmdlet to get a list of all namespaces on that server. It then loops through each namespace and uses the Get-DfsnFolder cmdlet to get a list of all folders in that namespace.

For each folder, the script uses the Get-DfsnFolderTarget cmdlet to get a list of all replicas (i.e., file servers) that host the folder. It then loops through each replica and writes its name and target path to the console.

Note that this script assumes that the DFS module is installed on the computer running the script, and that you have appropriate permissions to query DFS configuration information. If you encounter errors or permission issues, you may need to adjust the script or your system settings accordingly.

——————————————————————————————————————————

#Import DFS module

Import-Module DFSR

# Get DFS Namespace servers

$namespaceServers = Get-DfsnServerConfiguration | Select-Object -ExpandProperty ComputerName

# Loop through each namespace server and get its namespaces

foreach ($namespaceServer in $namespaceServers) {

    Write-Host “Namespace server: $namespaceServer”

    $namespaces = Get-DfsnRoot -ComputerName $namespaceServer

    foreach ($namespace in $namespaces) {

        Write-Host “Namespace: $($namespace.Path)”

        $folders = Get-DfsnFolder -Path $namespace.Path -AsHashTable

        foreach ($folder in $folders.GetEnumerator()) {

            Write-Host “Folder: $($folder.Value.Path)”

            $replicas = Get-DfsnFolderTarget -Path $folder.Value.Path

            foreach ($replica in $replicas) {

                Write-Host “Replica: $($replica.TargetPath) on $($replica.TargetServerName)”

            }

        }

    }

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: