Hi.
I want to get notification whenever a script exits with error status. For this purpose I’ve done the following:
I thought this would make scripts exiting with status error instead getting status failed, thus triggering the notification. However, my scripts still get status “error” and thus the trigger isn’t triggered. When I put “$ErrorActionPreference = ‘Stop’“ at the top of a script everything works for that script (I get a notification when it fails), just don’t want to do this in each and every script…
Am I going about this the wrong way?
edit: In the script setting ErrorActionPreference I put a line putting something in a log file just to check that it’s really executing, and it is.
What I do is create a trigger for completed jobs. Then the script checks the status of the job ($job.status.value) and sends an alert based on status.
$status = $job.status.value
if ($status -eq 'Error'){
Send-AlertFunction
}What I do is create a trigger for completed jobs. Then the script checks the status of the job ($job.status.value) and sends an alert based on status.
Ah, of course… Yes, that is a much clener solution, thanks!