Check exit status of PS script with custom success criteria

We have a custom powershell script for Windows Update and based on the exit value from the script we would like to either run the task again (as new updates can become available after reboot) or mark the task complete. I had theorised that I could use exit-status of the PS script to set the success value of a task and then schedule the action to re-run until successful. Is this possible? Currently I can’t seem to “fail” the task based on the exit value. I’ve tried setting a custom success criteria and evaluating it, but I barely understand the relevance language and I feel I’m missing something essential. I’ve included the task and the success criteria I’ve tried so far.

Action script (slightly abbreviated):

action uses wow64 redirection false
waithidden “{parameter “PowerShellexe”}” -file “C:\autopatch\bin\autopatch-server.ps1”
action uses wow64 redirection {x64 of operating system}

parameter “exitCode” = “{if exist exit code of action then exit code of action as string else “1”}”

exit {parameter “exitCode”}

Success Criteria:

exit code of action != “0”

Any tips? We have to run windows patching in a relative small time frame, once every month.

You can coerce a failure with something like

continue if {exit code of action = 0}

1 Like