2

好吧,我不知所措>。>我已经尝试过尝试/捕获和陷阱功能,但它不会捕获这个错误......

# 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
4

1 回答 1

2

尝试这个:

$Computers = Get-Content $Computers_Path -ea stop

这让trap捕获异常。

于 2012-11-02T14:24:33.383 回答