In this lab's case I've been using the following servers to create the root namespace:
- lab-dc001: This is the Windows Server 2012 R2 Domain Controller
- lab-dfs001: This is the first DFS Server
- lab-dfs002: This is the second DFS Server
# Parameters
$DFS_Root = "lab-dfs001"
$DFS_Secondaries = "lab-dfs002"
$DFS_Domain = "katalykt.lan"
$DFS_Namespace = "root"
$DFS_SmbPath = "E:\DFS\root"
$DFS_Servers = $DFS_Root, $DFS_Secondaries
# Install the DFS Namespace & Replication features
$DFS_Servers | ForEach-Object {Install-WindowsFeature -ComputerName $_ -Name FS-DFS-Namespace,FS-DFS-Replication -IncludeManagementTools}
# Create the Local Folders
$Sessions_DFS = New-PSSession -ComputerName $DFS_Servers
Invoke-Command -Session $Sessions_DFS -Script { New-Item $args[0] –Type Directory } -ArgumentList $DFS_SmbPath
$Sessions_DFS | Remove-PSSession
# Create the Local Shares
$CIMs_DFS = New-CimSession -ComputerName $DFS_Servers
New-SmbShare –Name $DFS_Namespace –Path $DFS_SmbPath -CimSession $CIMs_DFS
$CIMs_DFS | Remove-CimSession
# Create the main DFS Namespace root
New-DfsnRoot -TargetPath ("\\{0}\{1}" -f $DFS_Root, $DFS_Namespace) -Type DomainV2 -Path ("\\{0}\{1}" -f $DFS_Domain, $DFS_Namespace)
# Add additional targets to our DFS Namespace
$DFS_Secondaries | ForEach-Object {
New-DfsnRootTarget -Path ("\\{0}\{1}" -f $DFS_Domain, $DFS_Namespace) -TargetPath ("\\{0}\{1}" -f $_, $DFS_Namespace)
}