Powershell - 添加到 $Error

标签 powershell error-handling

使用 Powershell,如何向 $Error ArrayCollection 添加条目(或者可能,我应该向集合中添加更多内容)?

据我了解,使用 Write-Error 会输出错误并将条目添加到错误集合中。但我只想将一个条目直接添加到集合中,而不在当时输出。

最佳答案

ErrorAction 开关应该能够处理这个问题。

write-error "Something bad happened" -ErrorAction:SilentlyContinue

关于Powershell - 添加到 $Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12370392/

相关文章:

powershell - -replace 不将字符串替换为 "()"

c# - 如何从 C# 访问 PowerShell 主机

wpf - XML Findname 中的 PowerShell WPF 问题

Shell 脚本.....如果出错,请改为执行此操作

ruby-on-rails - Rails、Capistrano、Nginx、Unicorn - 应用程序已经初始化(RuntimeError)

php - 是否可以忽略 PHP 中的特定错误?

powershell - 如何使函数成为 cmdlet 的别名

sql-server - 了解 SQL 错误处理脚本

mysql - 如何在 Go-Gorm 中禁用默认错误记录器

Powershell 在单个命令行上组合变量表达式