I am looking for a PowerShell script that is capable to change the file server name in folder targets of all DFS namespaces
e.g. folder target '\\server1\Marketing\Branding' should become '\\server2\Marketing\Branding'
This is what I've come up so, far but the replace does not what I want it to do. Also I believe the code could probably structured much simpler:
$Namespaces = Get-DfsnRoot
$Namespaces | ForEach-Object {
$NSpath = $_.path
$NSfullpath = $NSpath + '\*'
$DFSTree = Get-DfsnFolder $NSfullpath
$DFSTree | ForEach-Object {
$DFSTarget = Get-DfsnFolderTarget $_.Path
$DFSTarget -replace "server1", "server2"
Set-DfsnFolderTarget -Path $DFSTarget.Path -TargetPath $DFSTarget.TargetPath -WhatIf
$DFSTarget -replace "server2", "server1"
Remove-DfsnFolderTarget -Path $DFSTarget.Path -TargetPath $DFSTarget.TargetPath -WhatIf
}
}
Any help is much appreciated!