powershell - powershell 中是否有相当于 "... || die"的值?

标签 powershell

有点像 <statement> || die在 perl 中,我可以将其与每个关键语句放在一起,以避免在出现问题时用脚本的其余部分打扰 powershell。

最佳答案

大多数命令支持 -ErrorAction通用参数。指定 -ErrorAction Stop通常会在出现错误时停止脚本。见 Get-Help about_CommonParameters .

默认情况下,-ErrorActionContinue .您可以通过更改 $ErrorActionPreference 的值来更改默认选项。 .见 Get-Help about_Preference_Variables .

如果冗长真的是一个问题,-ErrorAction别名为 -ea .

关于powershell - powershell 中是否有相当于 "... || die"的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29411390/

相关文章:

sharepoint - 从存储在文档库中的 Excel 中获取数据并使用 powershell 将其显示在列表中

powershell - 双下划线 ($_.value__) 是什么意思?

azure - 如何在函数中使用Azure CLI函数

将特定 PDF 页面打印成图像的 Powershell 脚本

PowerShell,如果您不属于域,是否可以将 SID 转换为 ntaccount?

java - 从 Java 调用 Powershell 会无限执行

azure - 通过 powershell 的 Azure VM 的 Powerstate

windows - Connect-AzAccount 更改浏览器

powershell - 如何从 powershell 中带参数调用 exe?

azure - 获取-AzResourceGroup : 'this.Client.SubscriptionId' cannot be null