Windows PowerShell 错误处理与调试指南
1. 错误处理
在 Windows PowerShell 中,错误处理是一个重要的环节,许多 cmdlet 支持 ErrorAction 和 ErrorVariable 这两个常见参数,它们在可能出现错误的场景中尤为重要。
1.1 使用 ErrorAction 参数
–errorAction 参数用于指定 cmdlet 的错误处理动作,它会覆盖 $ErrorActionPreference 变量中设置的值。以下是使用该参数的示例步骤:
1. 将当前工作文件夹设置为不包含名为 Fred.txt 文件的文件夹。
2. 运行以下命令确认 $ErrorActionPreference 的值:
$ErrorActionPreference
- 依次运行以下命令:
get-childitem Fred.txt –ErrorAction SilentlyContinue ; write-host “We got here”
get-childitem Fred.txt –ErrorAction Continue; write-host “We got here”
get-chil
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



