腳本是自我解釋的,但我不知道如何讓它工作。我想弄清楚如何傳遞變量$ComputerPath
的功能和在腳本中設置$ComputerPath
嵌套變量的問題
Function CheckPath {
While (!$args[0]) {
Write-Host "`nVariable Undefined"
$Args[0] = Read-Host "Enter Valid Path"
}
while (!(test-path $Args[0])) {
Write-Host "Unable To Location Files, Please Check Again."
$args[0] = Read-Host "Enter Valid Path"
}
}
$ComputersPath = "missingfile.txt"
$ComputersPath
CheckPath $ComputersPath
$ComputersPath
我的結果
PS Z:\Powershell Scripting\Test Lab> .\TestFunction.ps1
missingfile.txt
Unable To Location Files, Please Check Again.
Enter Valid Path: log.txt
missingfile.txt
PS Z:\Powershell Scripting\Test Lab>
試圖改變,但仍然無濟於事。一直玩這樣的4小時,沒有運氣>> – user1451070
@ user1451070在我編輯的答案中嘗試腳本,並看看ShayLevi答案。 –
嘗試過兩種方法,除了它們不會更新變量外,它們都起作用。 – user1451070