我想在遠程計算機上搜索擴展名為 .2fa 的檔案。我可以找到我想要的檔案,但是要花很長時間才能到達第二臺計算機,因為它會掃描所有 windows 檔案。
我嘗試了 -exclude 和 where 引數,但它們不起作用。
請你幫助我好嗎?謝謝。
$ServerList = Import-Csv 'C:\PC.CSV'
$result = foreach ($pc in $ServerList.barkod) {
$exclude = '*ProgramData*','*Program Files*','*Program Files (x86)*','*Windows*'.'*winupdate*'
$sourcepath = 'c$'
Get-ChildItem -Path \\$pc\$sourcepath -Recurse | Where-Object { $_.Name -like "*.2fa" } |
where {$_.name -notin $Exclude}
}
$result
我試過了
-排除 $exclude -where {$_.name -notin $Exclude}
uj5u.com熱心網友回復:
-exclude 不適用于子目錄或 -filter:
Get-ChildItem -Path \\$pc\$sourcepath\ -exclude $exclude |
get-childitem -recurse -filter *.2fa
uj5u.com熱心網友回復:
由于您要查找具有特定擴展名的檔案-Filter,因此請使用該引數。這將是僅搜索.2fa檔案而忽略所有其他檔案的最快選項。(過濾器適用于 Name 屬性)
如果你想搜索 C: 驅動器,你一定會遇到拒絕訪問例外,因為要使用帶有 Where-Object 子句的后處理排除檔案夾名稱串列,
Get-ChildItem將嘗試在這些檔案夾中搜索你需要附加-ErrorAction SilentlyContinue到命令
$exclude = 'ProgramData','Program Files','Program Files (x86)','Windows'.'winupdate'
# create a regex string you can use with the `-notmatch` operator
# each item will be Regex Escaped and joined together with the OR symbol '|'
$excludeThese = ($exclude | ForEach-Object { [Regex]::Escape($_) }) -join '|'
$ServerList = (Import-Csv 'C:\PC.CSV').barkod
$sourcepath = 'c$'
$result = foreach ($pc in $ServerList) {
Get-ChildItem -Path "\\$pc\$sourcepath" -Filter '*.2fa' -File -Recurse -ErrorAction SilentlyContinue |
Where-Object {$_.DirectoryName -notmatch $excludeThese}
}
$result
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/534701.html
標籤:电源外壳获取子项目
