该脚本是不言自明的,但我不知道如何让它工作。我想弄清楚如何将变量传递$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>