【发布时间】:2020-11-03 11:48:21
【问题描述】:
当我想在遇到错误时停止 Powershell 脚本,我应该如何停止脚本?
-ErrorAction -Stop ..
try {
foo.bar
catch{
$ErrorMsg = "An error occured during foo.bar"
Write-Error -Message $ErrorMsg -ErrorAction Stop
}
或
try {
foo.bar
catch{
$ErrorMsg = "An error occured during foo.bar"
Write-Error -Message $ErrorMsg
exit
}
什么是最佳实践和推荐?
【问题讨论】:
标签: powershell