嘗試通過 powershell 和帶有假定目錄的 CSV 檔案來定位存在或不存在的目錄。我們可以讓它運行并顯示在控制臺中,但它不會將結果匯出到 txt 檔案。它創建了檔案,但它是空的。任何幫助都是有用的!
Import-Csv .\missingpaths.csv | ForEach {If (Test-Path -Path $_.Path) {Write-Output"$($_.Path) exists" } Else {Write-Output "$($_.Path) does NOT exist" $_.File | Out-File .\MissingCSV.csv -Append }}
uj5u.com熱心網友回復:
在Out-File你的代碼是關于else唯一的陳述句(他原因之一格式化和縮進是非常重要的,因為它可以幫助你避免這些問題),除非這是故意的,你只想要匯出這些路徑不存在。
} Else {
Write-Output "$($_.Path) does NOT exist" $_.File |
Out-File .\MissingCSV.csv -Append
}
試試這個:
Import-Csv .\missingpaths.csv | ForEach-Object {
[pscustomobject]@{
Path = $_.Path
TestPath = ('Does not Exist', 'Exist')[(Test-Path $_.Path)]
}
} | Export-Csv path/to/result.csv -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/389634.html
標籤:电源外壳
