How to Managed Distributed File System (DFS) Links with PowerShell

Distributed File System (DFS) Links reduce the complexity of working with network file shares. DFS Links allow users and applications to access a “virtual path name” to connect to shared folders. We can create DFS links with PowerShell.

This “virtual namespace” enables administrators to present shared folders located on different servers, or even change a shared folder’s location, completely transparent to that folder’s consumers.

Users will not need to update bookmarks, and applications will not be required to be updated with new paths when File Servers change.

Benefit to Users

For the users, access to network share folders is simplified down to a “namespace\FolderName” format, a reduction in the complexity associated with folders stored on remote servers.

Are you an IT pro ready to take your career to the next level? If so, join our contributor program! You don't have to be an expert presenter, a Microsoft MVP or even have a blog. We want your knowledge! You will be coached on presentation skills, become a member of our awesome community and get paid some nice side hustle income every, single month! Sign up today!.

Benefit to Applications

For applications, hard-coded paths to resources on the network do not have to be changed due to a change in the network path. A simple update to the DFS Link and the application will continue to access the resources at their new location.

Prerequisites for the DFS Server Role

  • Active Directory
  • File and Storage Services role installed on a Windows Server:
  • Windows Server (Semi-Annual Channel)
  • Windows Server 2016
  • Windows Server 2012 R2
  • Windows Server 2012
  • Windows Server 2008 R2 Datacenter/Enterprise

Prerequisites for PowerShell cmdlets:

  • An administrator account with the proper permissions
  • RSAT Tools with the ‘File Services Tools – DFS Management Tools’ installed

Enabling DFS Tools with PowerShell

Download and install RSAT
Next, you need to Enable the Distributed File System Tools
* Open PowerShell as an Administrator
* Run the Install-WindowsFeature command:

How to Set Up DFS with PowerShell

We first need to install all of the necessary Windows features. This will install DFS Management GUI, the DFS Namespaces module for Windows PowerShell to create DFS links with PowerShell and manage them, and command-line tools, but it does not install any DFS services on the server.

Administration of DFS Links

You can administer namespaces by using DFS Management GUI, the DFS Namespace (DFSN) Cmdlets in Windows PowerShell, the DfsUtil commands, or scripts that call WMI.

Common PowerShell commands

Get-DfsnRoot – Discover all DFS Namespaces in the current domain
– Commonly used to check for available namespaces in the current domain

New-DfsnFolder – Create a new DFS Folder Name
– Commonly used to create a new DFS Folder in a NameSpace

New-DfsnFolderTarget – Assign path(s) to a DFS Folder Name
– Commonly used to assign one or more network folder paths to a DFS Folder

Remove-DfsnFolderTarget – Removes a path from a DFS Folder but does not remove the DFS Folder.
– Commonly used to remove one or more network folder paths from a DFS Folder

Remove-DfsnFolder – Removes a folder and all its paths
– Commonly used to remove a DFS Folder from a NameSpace

Finding DFS namespaces with PowerShell

We’ll start out by getting an idea of all the online and available NameSpaces in the current Domain using the cmdlet Get-DfsnRoot.

This shows that there are two NameSpaces that are Online in this domain.

Finding DFS folders with PowerShell

Using the Get-DfsnFolder command we can list the DFS Folders in each NameSpace.

From this output, we can see that in the AppRoot NameSpace this is not a DFS Folder named PowerShell.

Creating DFS Link Folders with PowerShell

In this example, we have a replicated folder named PowerShell on our 3 File Services servers
* FileServer01
* FileServer02
* Datacenter

The goal is to share this replicated folder with our Admins using a single path.

To do this, we’ll create a new DFS Link folder in the AppRoot NameSpace called PowerShell using New-DfsnFolder and point it to the Datacenter server’s FileShare, set the DFS Folder State to Online and set the TargetPath state to Online.

In the DFS Management GUI, we can see that the “PowerShell” DFS Folder does not exist.

Our Folder Target UNC Path

Run PowerShell and check for the DFS FolderTargetPath

\\\AppRoot\PowerShell – if it doesnt exist it will write the output ‘Path not found. Clear to proceed’ in green text in the terminal window.

From the output we see that:
* Path has been created
* Referral Priority Class is set to Global-High
* State is Online

The GUI confirms what PowerShell told us.

and our path is now available in Windows Explorer

Creating DFS Folder Targets with PowerShell

Now that we successfully created the “Powershell” DFS Folder in our NameSpace, we’re going to add an additional Folder Target Path to it and set that path as Online using New-DfsnFolderTarget.

Up to this point, we have two of our three Server Paths added, and online. For our last Folder Path, we want to add the path but not make it available to users. So let’s add a Folder Target Path to our “PowerShell” DFS Folder and this time set the DFS Folder Path State to Offline we will again use New-DfsnFolderTarget

FileServer01 and Datacenter’s path is currently Online
FileServer02‘s state has been set to Offline

Setting DFS Folders Targets to Offline or Online with PowerShell

We can change which servers are the Online and Offline hosts, and even which will be our server will be the primary host of the file path using Set-DfsnFolderTarget.

As you can see below in the ScreenCap FileServer01‘s path has changed to Offline
Datacenter server’s ReferralPriorityClass has switched to sitecost-normal from global-high
Also, notice that FileServer02‘s path has changed its state to Online and its ReferralPriorityClass has switched to global-high

Removing DFS folder target paths with PowerShell

I try to vaccinate my code against the Fat Finger Flu as much as possible. Here we will try to install a “Safety Net” before removing one of the FolderTargetPaths by making sure that it is at least Offline before deleting it.

So long path FileServer01

For those who prefer to “cowboy” it up and forego the “safety net” option, we can accommodate you, brave souls, also.

We’ve bid adieu to the path to FileServer02

Removing DFS Folders with PowerShell

It’s has been a long and winding path, but the time for our DFS Link has come to an end. We can Remove the PowerShell folder, DFS Link, using Remove-DfsnFolder.

A quick double-check of the DFS Management GUI shows our DFS Link is no more.

One final note…These commands are only removing the DFS Links, no folders were harmed in the production of this demo.

For More Information about DFS Links

How to manage Distributed File System links with PowerShell

How to manage Distributed File System links with the GUI

Other Helpful TechSnips

Josh King’s Snip on Splatting at

Matt McElreath’s Snip on Using Visual Studio Code to do Splatting at

Microsoft – DFS Overview

2 Replies to “How to Managed Distributed File System (DFS) Links with PowerShell”

  1. Are the RSAT tools for 2019 server core not installable? I get an error in powershell if I try to install
    Install-WindowsFeature “RSAT-DFS-Mgmt-Con”

Leave a Reply

Your email address will not be published. Required fields are marked *