【问题标题】:How to extract the DFS properties of a folder using powershell如何使用PowerShell提取文件夹的DFS属性
【发布时间】:2014-08-11 16:24:30
【问题描述】:

我想使用 powershell 从文件夹的 DFS 属性选项卡中提取信息。

基本上我想遍历文件夹结构并递归检索每个文件夹的 dfs 信息。

【问题讨论】:

  • 您有 Server 2012 还是 Windows 8?如果是这样,您应该拥有轻松获取该信息所需的 cmdlet。查看this link 了解更多信息。
  • @TheMadTechnician 不,我正在使用 Windows 7。
  • 我没有要测试的东西,但这看起来应该可以工作:dfscommands.codeplex.com

标签: powershell microsoft-distributed-file-system


【解决方案1】:

试试dfsutil 命令:

PS C:\> dfsutil client property state $DFSPath

【讨论】:

  • 带有一点解释的答案通常更有用。
  • 我认为这个答案也不是真正的“使用 PowerShell”。
【解决方案2】:

使用 WMI

如果您有权查询 WMI,则可以使用Get-WmiObject PowerShell cmdlet;你应该能够适应这个例子:

$DfsProvider = "SERVER"
$DfsPath = "\\SOME\DFS\Path"

Get-WmiObject -ComputerName $DfsProvider -Class Win32_DFSTarget `
  -Filter "SELECT ServerName,ShareName,LinkName FROM Win32_DFSTarget WHERE LinkName = '$DfsPath'"

【讨论】:

    【解决方案3】:

    这是帮助我解决同样问题的 Powershell sn-p:

    (Get-DfsnRoot -Domain example.net).Path |
        % { (Get-DfsnFolder -Path (Join-Path -Path $_ -ChildPath "\*")).Path } |
            % { Get-DfsnFolderTarget -Path $_ | select Path, TargetPath } |
                sort Path |
                    ft -autosize
    

    一些备注:

    • 它使用来自DFSR module for Powershell 的 cmdlet,我相信它自/适用于 Windows Server 2012 R2(您可能需要先安装/启用它)。
    • Get-DfsnFolder -Path 参数末尾的\* 很重要!没有它,我得到一个“CimException”;我首先尝试了一个简单的字符串连接,但没有成功,这就是我使用 Join-Path 的原因。
    • 我只对目标路径感兴趣,因此在上面的代码 sn-p 中没有考虑其他 DFS 属性。

    输出应如下所示:

    Path                             TargetPath
    ----                             ----------
    \\example.net\Admin\AdminScripts \\FS101XY0123.example.net\SysAdmin$\AdminScripts
    \\example.net\Admin\Setup        \\fs302az8901.example.net\SysAdmin$\Tools\Setup
    \\example.net\Admin\Tools        \\fs202zz4567.example.net\SysAdmin$\Tools
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 2018-04-19
      • 1970-01-01
      • 2022-07-28
      • 2021-06-17
      • 1970-01-01
      相关资源
      最近更新 更多