我有存盤漫游用戶組態檔的驅動器:
U:\Users\john.doe
U:\Users\john.wick
U:\Users\john.smith
我需要檢查用戶的個人資料中是否存盤了帶有 *.pdf 擴展名的檔案
$a = Get-ChildItem "U:\users\" -Include *.pdf -Recurse | select FullName
foreach ($b in $a){
Write-Output $b
}
輸出
U:\Users\john.wick\desktop\file.pdf
U:\Users\john.wick\documents\a.pdf
U:\Users\john.doe\desktop\1.pdf
..................................
我需要撰寫列以從路徑中提取用戶名,以及一列具有完整檔案路徑。怎么做 ?
john.doe
john.wick
--------
uj5u.com熱心網友回復:
呼叫Get-ChildItem without -Recurse以發現組態檔檔案夾,然后使用Where-Object Get-ChildItem查找包含 pdf 的檔案夾:
$profilesWithPDFs = Get-ChildItem U:\Users\ -Directory |Where-Object { $_ |Get-ChildItem -File -Recurse -Filter *.pdf |Select -First 1 }
找到相關檔案夾后,您只能獲取名稱:
$profilesWithPDFs |ForEach-Object -MemberName Name
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454127.html
