我正在寻找一个能够更改所有 DFS 命名空间的文件夹目标中的文件服务器名称的 PowerShell 脚本
例如文件夹目标“\\server1\Marketing\Branding”应变为“\\server2\Marketing\Branding”
这就是我到目前为止所提出的,但替换并没有达到我想要的效果。我还相信代码的结构可能会更简单:
$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
}
}
非常感谢任何帮助!
最佳答案
万一有人像我一样遇到这个问题。这是问题的解决方案:
$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
}
}
关于powershell - 替换 DFS 文件夹目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44460356/