你可以嘗試像htis
Get-ChildItem -Filter "abc" -Recurse -Path "\\myserver\share" | #Find abc
Where-Object { $_.PSIsContainer } | #Get only abc-folders
Get-ChildItem -Recurse | #Search through each abc-folder
Where-Object { !$_.PSIsContainer } #Get only files
,如果你的服務器或使用psremoting上本地運行腳本的性能會更好(例如,使用Invoke-Command
)。問題在於,它在遞歸搜索所有文件和文件夾之前,從第一行Get-ChildItem
行中的搜索結果中刪除文件。
如果您有PS 3.0或PS 4.0,你也可以使用:
Get-ChildItem -Filter "abc" -Recurse -Path "\\myserver\share" -Directory | #Find abc-folders
Get-ChildItem -Recurse -File #Get files inside those folders
伴侶你的傳奇,感謝堆。 :) – user3467484