Run Script - Powershell last exit codes are not working as expected

book

Article ID: 169494

calendar_today

Updated On:

Products

Task Server

Issue/Introduction

Some syntax in powershell scripts do not cause the script task to exit with the proper exit code.

Example:
$Host.SetShouldExit(99) 
Causes the script to exit with error code 0 making it seem like everything in the script was successful

Cause

This was caused by the fix to another issue.

Environment

ITMS 7.x, 8.x

Resolution

There are three solutions to this issue.

  1. Use different syntax. For example:
    • Environment]::Exit(98)
  2. If you are still using ITMS 7.6, 8.0 or 8.1, upgrade to ITMS 8.5 where this issue has been addressed.