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!
In case anybody stumples upon this question, as I did. This is a solution to the problem:
$Namespaces = Get-DfsnRoot
$Namespaces | ForEach-Object {
$NSpath = $_.path
$NSfullpath = $NSpath + '\*'
$DFSTree = Get-DfsnFolder $NSfullpath
$DFSTree | ForEach-Object {
$DFSTarget = Get-DfsnFolderTarget $_.Path
New-DfsnFolderTarget -Path $DFSTarget.Path -TargetPath ($DFSTarget.TargetPath -replace "server1", "server2") -WhatIf
Remove-DfsnFolderTarget -Path $DFSTarget.Path -TargetPath $DFSTarget.TargetPath -WhatIf
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With