I have a script (webdeploy.ps1) that runs fine locally or remotely via invoke-command. For one reason or another, webdeploy.ps1 will fail and exit before reaching the end of the script due to some catastrophic error that can't be handled by webdeploy.ps1 (ie. out of disk space). The script terminates after a Write-Error documenting the error. End user is notified. All is good.
Now when webdeploy.ps1 is executed remotely by Invoke-Command -asjob, the job state always return "Completed" even though the script failed. Are there any ways to set the job state as failed such that when I run get-job I can immediately see which server failed / completed successfully.
foreach ($webserver in $webServers)
{
Invoke-Command -ComputerName $webServer -FilePath .\webdeploy.ps1 -AsJob -JobName "WebDeploy"
}
get-job | select name, id, State, Location | Format-Table -AutoSize
Name Id State Location
---- -- ----- --------
WebDeploy 102 Completed dev-web1
WebDeploy 104 Completed dev-web2
receive-job
? Sometimes errors are hidden there in my (limited) experience. – Troy