| 用途 | 统一错误响应策略 |
|---|---|
| 语法 | $ErrorActionPreference = 'Stop';-ErrorAction 逐命令覆盖 |
| 取值 | Continue(默认)、Stop、SilentlyContinue、Inquire、Ignore |
常用示例
常用示例
$ErrorActionPreference = 'Stop'
try { Get-Item D:\nope } catch { $_.Exception.Message }
Get-ChildItem D:\nope2 -ErrorAction ContinueStop 让非终止错误变成可捕获的终止错误,这是 try/catch 能兜住一切的前提。