Powershell |无法找出陷阱功能

时间:2012-11-02 14:08:37

标签: powershell

好的我不知所措>。>我尝试过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

1 个答案:

答案 0 :(得分:2)

试试这个:

$Computers = Get-Content $Computers_Path -ea stop

这使得trap能够捕获异常。