powershell - 替换 DFS 文件夹目标

标签 powershell microsoft-distributed-file-system

我正在寻找一个能够更改所有 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/

相关文章:

json - 从JSON创建CSV文件时Powershell脚本性能不佳

azure - 是否可以在从 PowerShell 创建 Azure VM 时安装应用程序?

azure - 使用 powershell 在 Azure VM 上启动和停止 Windows 服务

java - 以编程方式获取 DFS/UNC 信息 - Java

hadoop - 允许指定文件存储在哪台机器上的分布式文件系统

hadoop - hadoop_starting daemon_no文件或目录错误

powershell - 查找以特定单词开头的行,然后替换该行中两个单词之间的字符串

powershell - Copy-Item 是否更改 PowerShell 中目标参数的类型

hadoop - 错误:$ hadoop namenode -format

file - Hadoop DFS放置创建_COPYING_暂存文件