好的我不知所措>。>我尝试过try / catch和trap函数,它不会发现这个错误......
# Adjustable Variables
$Computers_Path = ".\Compuers.txt"
$Log_Path = ".\Log.txt"
# Script Specific Variables
# Validate Adjustable Variables
TRAP { Write-Host "Unable to locate list of computer names at $Computers_Path"; Continue; }
$Computers = Get-Content $Computers_Path
答案 0 :(得分:2)
试试这个:
$Computers = Get-Content $Computers_Path -ea stop
这使得trap
能够捕获异常。