如何向powershell表明作业失败

时间:2015-12-07 20:52:30

标签: powershell

我正在编写一个PowerShell脚本,我希望它同时运行多个进程。如果任何作业失败,我希望它失败。所以我有一段看起来像这样的代码:

$job = Start-Job -ScriptBlock {
   #do stuff
   if ($LASTEXITCODE -ne 0)
   {
      #indicate that the job has failed.
   } 
}

如何表明作业失败?

1 个答案:

答案 0 :(得分:3)

要指示失败的作业,请尝试使用以下命令:

[System.Environment]::Exit(1)

这将显示为'失败'也可能不那么好:

Throw "the job has failed"
相关问题