---
title: "Efficient DFS Management with PowerShell Scripts"
description: "Automate and manage every aspect of DFS using comprehensive PowerShell scripts."
canonical: "https://adamtheautomator.com/dfs-powershell-scripts/"
---

# Efficient DFS Management with PowerShell Scripts

> Automate and manage every aspect of DFS using comprehensive PowerShell scripts.

Source: https://adamtheautomator.com/dfs-powershell-scripts/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Efficient DFS Management with PowerShell Scripts](https://adamtheautomator.com/wp-content/uploads/2019/07/dfs-overview.png)

# Efficient DFS Management with PowerShell Scripts

[![](https://secure.gravatar.com/avatar/c3f0233f6307bf41ee8eba5ba5aecb3b0d80054023377040f4cecbc595249a05?s=192&d=mm&r=g)Scott Hurst](https://adamtheautomator.com/author/scott/)26 July 20196 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[DFS](/tag/dfs/)[PowerShell](/tag/powershell/)

Table of Contents

*   [DFS Benefits](#dfs-benefits)
*   [Prerequisites for the DFS Server Role](#prerequisites-for-the-dfs-server-role)
*   [Prerequisites](#prerequisites-for-powershell-cmdlets-)
*   [Getting Set up for your DSC PowerShell Scripts](#getting-set-up)
*   [Common DFS Commands](#common-dfs-commands)
*   [Finding DFS Namespaces](#finding-dfs-namespaces)
*   [Finding DFS folders](#finding-dfs-folders)
*   [Creating DFS Link Folders for DSC PowerShell Scripts](#creating-dfs-link-folders-with-powershell)
*   [Creating DFS Folder Targets](#creating-dfs-folder-targets)
*   [Setting DFS Folders Targets to Offline or Online](#setting-dfs-folders-targets-to-offline-or-online)
*   [Removing DFS folder target paths with PowerShell](#removing-dfs-folder-target-paths-with-powershell)
*   [Removing DFS Folders](#removing-dfs-folders)
*   [Summary](#summary)

Get ready to learn how to write better DFS PowerShell scripts using the knowledge you gain in this tutorial. In this post, you’ll learn all about managing DFS links in PowerShell!

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

> _This blog post has a companion video created by [TechSnips contributor, Scott Hurst](https://techsnips.io/contributors/scott-hurst/). Feel free to have a watch or, if you prefer text, read on!_

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. You can [create DFS _links_ with PowerShell](https://adamtheautomator.com/teams-webhooks/).

Whether you’re managing Active Directory or another DFS product, writing DFS PowerShell scripts will help you wrangle whatever issues you run int.

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.

## DFS Benefits

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.

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

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

## Getting Set up for your DSC PowerShell Scripts

First, d[ownload and install RSAT](https://www.microsoft.com/en-us/download/details.aspx?id=45520). Next, you 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.

```powershell
Install-WindowsFeature FS-DFS-Namespace, RSAT-DFS-Mgmt-Con
```

## Common DFS Commands

You can administer namespaces by using _DFS Management_ GUI, the _DFS Namespace (DFSN)_ cmdlets in PowerShell, the _DfsUtil_ commands, or scripts that call WMI.

Some common PowerShell commands are:

*   `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

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

```powershell
$Domain = 'tech.io'
(Get-DfsnRoot -Domain $Domain).Where( {$_.State -eq 'Online'} ) | Select-Object -ExpandProperty Path
```

This shows that there are two _namespaces_ that are `Online` in this domain.

![Finding DFS roots](/wp-content/uploads/2019/07/image-55.png)

Finding DFS roots

## Finding DFS folders

Using the `Get-DfsnFolder` command we can list the DFS _folders_ in each _namespace_.

```powershell
$Domain = 'tech.io'
Get-DfsnFolder -Path "\\$Domain\AppRoot\*" | Select-Object -ExpandProperty Path
Get-DfsnFolder -Path "\\$Domain\DFSRoot\*" | Select-Object -ExpandProperty Path
```

From this output, we can see that in the _AppRoot namespace_ this is not a DFS _folder_ named _PowerShell_.

![Finding DFS folders](/wp-content/uploads/2019/07/image-56.png)

Finding DFS folders

## Creating DFS Link Folders for DSC PowerShell Scripts

In this example, we have a replicated folder named _PowerShell_ on our three file servers; _FileServer01, FileServer02_ and _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 file share. We’ll set the DFS _folder_ _state_ to _Online_ and set the _TargetPath_ _state_ to _Online_.

```powershell
$Domain = 'tech.io'
try {
    Get-DfsnFolderTarget -Path "\\$Domain\AppRoot\PowerShell" -ErrorAction Stop
} catch {
    Write-Host "Path not found. Clear to proceed" -ForegroundColor Green
}

$NewDFSFolder = @{
    Path = "\\$Domain\AppRoot\PowerShell"
    State = 'Online'
    TargetPath = '\\datacenter\FileShare\PowerShell'
    TargetState = 'Online'
    ReferralPriorityClass = 'globalhigh'
}

New-DfsnFolder @NewDFSFolder

# Check that folder now exists:
Get-DfsnFolderTarget -Path "\\$Domain\AppRoot\PowerShell"

# Check that the new DFS Link works using Windows Explorer
Invoke-Expression "explorer '\\$Domain\AppRoot\PowerShell\'"
```

In the DFS Management GUI, we can see that the _PowerShell_ DFS _folder_ does not exist.

![Inspecting DFS folders in the GUI](/wp-content/uploads/2019/07/img_5b687495993a6.png)

Inspecting DFS folders in the GUI

![The folder target UNC path](/wp-content/uploads/2019/07/img_5b6874a6c6412.png)

The folder target UNC path

Let’s now execute Windows Explorer from within a PowerShell console and confirm it doesn’t exist.

```powershell
Invoke-Expression "explorer "\\$Domain\AppRoot\PowerShell"
```

If the folder does not exist it will write the output _Path not found. Clear to proceed_ in green text in the terminal window as you can see below.

From the output we see that the folder has been created, the `Referral Priority Class` is set to `Global-High` and the `State` is `Online`.

![Inspecting DDS referral priority class and state](/wp-content/uploads/2019/07/img_5b6874b65cc76.png)

Inspecting DFS referral priority class and state

The GUI also confirms what PowerShell told us.

![Inspecting DFS referral priority class and state](/wp-content/uploads/2019/07/img_5b6874c5b2523.png)

Inspecting DFS referral priority class and state

and our path is now available in Windows Explorer.

![DFS path available in Windows Explorer](/wp-content/uploads/2019/07/img_5b6874e050a8f.png)

DFS path available in Windows Explorer

## Creating DFS Folder Targets

Now that we successfully created the _Powershell_ DFS _folder_ in the _namespace_, add an additional _folder target path_ to it and set that path as _Online_ using `New-DfsnFolderTarget`. DFS PowerShell scripts allow you to add any number of components.

```powershell
$Domain = 'tech.io'

## Splat the settings for easy readibility
$NewTPS = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\FileServer01\FileShare\PowerShell'
    State = 'Online'
}

## Add new folder located on the 'FileServer01' server & set Online
New-DfsnFolderTarget @NewTPS
```

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](https://adamtheautomator.com/powershell-scheduled-task/)_ [DFS _folder_ and this time set](https://adamtheautomator.com/powershell-scheduled-task/) the DFS older Path State to offline we will again use `New-DfsnFolderTarget`.

```powershell
$Domain = 'tech.io'
## Splat the settings for easy readibility
$NewTPS = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\FileServer02\FileShare\PowerShell'
    State = 'Offline'
}

## Add new folder located on the 'FileServer02' server & set to Offline
New-DfsnFolderTarget @NewTPS
## Check that folder now exists:
```

![Creating a new DFS folder target](/wp-content/uploads/2019/07/img_5b6874fab7095.png)

Creating a new DFS folder target

You can see that _FileServer01_ and _Datacenter’s_ path is currently `Online` and _FileServer02’s_ state has been set to `Offline`.

![DFS path status](/wp-content/uploads/2019/07/img_5b68750f66980.png)

DFS path status

## Setting DFS Folders Targets to Offline or Online

We can also 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`.

```powershell
$Domain = 'tech.io'

## Splatting the settings where the path pointed at the server named FileServer01
$ChangeTPsFS1 = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\FileServer01\FileShare\PowerShell'
    State = 'Offline'
}

## Set folder located on the server path 'FileServer01' to Offline
Set-DfsnFolderTarget @ChangeTPsFS1

## Splatting the settings where the path pointed at the server named FileServer02
$ChangeTPsFS2 = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\FileServer02\FileShare\PowerShell'
    State = 'Online'
    ReferralPriorityClass = 'globalhigh'
}

## Set folder located on the 'FileServer02' server to Online
Set-DfsnFolderTarget @ChangeTPsFS2

## Splatting the settings where the path pointed at the server named Datacenter
$ChangeTPsFS3 = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\datacenter\FileShare\PowerShell'
    ReferralPriorityClass = 'sitecostnormal'
}

## Change Priority of 'Datacenter' server folder path to 'Normal'
Set-DfsnFolderTarget @ChangeTPsFS3
```

As you can see below:

*   _FileServer01_‘s path has changed to `Offline`
*   _The Datacenter_ server’s `ReferralPriorityClass` has switched to `sitecost-normal` from `global-high`
*   _FileServer02_‘s path has changed its state to `Online`
*   FileServer02’s `ReferralPriorityClass` has switched to `global-high`

![New status of DFS](/wp-content/uploads/2019/07/img_5b6875250c9d8-2.png)

New status of DFS

## 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 _folders_ by making sure that it is offline before deleting it.

```powershell
# Check Target Path to 'FileServer01' server to Offline & Remove the Folder Target Path
if ((Get-DfsnFolderTarget -Path "\\$Domain\AppRoot\PowerShell" -TargetPath '\\FileServer01\FileShare\PowerShell').State -eq "Offline") {
    Remove-DfsnFolderTarget -Path "\\$Domain\AppRoot\PowerShell" -TargetPath '\\FileServer01\FileShare\PowerShell' -Force:$true
}
```

So long _FileServer01_ folder!

![FileServer01 folder is removed](/wp-content/uploads/2019/07/img_5b687534e4c78.png)

FileServer01 folder is removed

For those who prefer to forego the safety net option, we can accommodate you, brave souls, also.

```powershell
$Domain = 'tech.io'

## Splatting the settings where the path pointed at the server named 'FileServer02'
$DelFTS = @{
    Path = "\$Domain\AppRoot\PowerShell"
    TargetPath = '\FileServer02\FileShare\PowerShell'
}

##Delete the DFS FolderTarget
Remove-DfsnFolderTarget @DelFTS -Force:$true
```

We’ve bid adieu to the FileServer02 folder.

![FileServer02 fodder is removed](/wp-content/uploads/2019/07/img_5b68754740ec7.png)

FileServer02 fodder is removed

## Removing DFS Folders

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 and DFS _link_ using the `Remove-DfsnFolder` cmdlet.

```powershell
$Domain = 'tech.io'

## Delete the DFS Folder
Remove-DfsnFolder -Path "\$Domain\AppRoot\PowerShell" -Force:$true
```

![Removing DFS folder](/wp-content/uploads/2019/07/img_5b687558e2b5d.png)

Removing DFS folder

A quick double-check of the _DFS Management_ GUI shows our DFS _link_ is no more.

![Confirming DFS folder removal](/wp-content/uploads/2019/07/img_5b687567e2833.png)

Confirming DFS folder removal

## Summary

That’s it! You covered a winding road of DFS and PowerShell kung fu. By now I hope you have some acquired some code snippets to help you build better PowerShell DFS scripts!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fdfs-powershell-scripts%2F&text=Efficient%20DFS%20Management%20with%20PowerShell%20Scripts)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fdfs-powershell-scripts%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fdfs-powershell-scripts%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

![](https://adamtheautomator.com/wp-content/uploads/2025/06/featured-image-6.png)

### [How to Add Timeouts to Pester Tests with PowerShell Runspaces](/pester-test-timeout-runspaces/)

Prevent Pester tests from hanging indefinitely using PowerShell runspaces. Learn to handle variable scoping, module loading, TestDrive access, and stream capture challenges with timeout protection.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
