我想列出文件服务器上的所有文件名。此-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
}