Get-ChildItem -Recurse 文件共享

Get-ChildItem -Recurse 文件共享

我想列出文件服务器上的所有文件名。此-Recurse选项在文件共享中有效。

$shareName = "\\myFileServer\myShare01"
Get-ChildItem -Path $shareName -File -Recurse | Select FullName

FullName
--------
\\myFileServer\myShare01\test.txt
\\myFileServer\myShare01\testdir\anotherfile.txt

我如何才能-Recurse通过所有共享和文件myFileServer输出如下内容?

FullName
--------
\\myFileServer\myShare01\test.txt
\\myFileServer\myShare01\testdir\anotherfile.txt
\\myFileServer\myShare02\test2.txt
\\myFileServer\Testshare\test.txt

答案1

net view用于列出共享的powershell 脚本示例:

$server = "myServer.domain.com"

# use NET VIEW to list visible shares and select only the names
$shares = net view "\\$server" /all | 
  select -Skip 7 | 
  Where {$_ -match 'disk*'} | 
  Foreach {$_ -match '^(.+?)\s+Disk*'|out-null;$matches[1]}

# list files in share
Foreach ($share in $shares) {
  Get-ChildItem -Path "\\$server\$share" -File -Recurse | Select FullName 
}

相关内容