Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace DFS folder target

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!

like image 215
user7986342 Avatar asked Jan 23 '26 05:01

user7986342


1 Answers

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
    }
}
like image 122
Frank N. Avatar answered Jan 25 '26 19:01

Frank N.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!