Adding a custom exit code to a PowerShell Job


In some cases, users may wish to force a PowerShell Job to exit at a specific point and add a custom exit code.  In order to do this you can use the following variable in your PowerShell Source:


In this example, 411 is the custom exit code that is being specified and can be set to a users specific needs. This custom exit code can then be added to the Source Options tab in the Job properties. In our example above, the exit code of 411 signifies an Informational exit code value for the Job.

Have more questions? Submit a request


  • Avatar
    Chris Huckabee

    It'd be nice if JAMS could port the system $LASTEXITCODE to the JAMS exit code so you wouldn't have to add this to your scripts.

  • Avatar
    Gennaro Piccolo

    Hi Chris, if you're interested in submitting a JAMS enhancement request, you can do so here.

  • Avatar
    Paul Harman

    Is this the same as Exit 411?

  • Avatar
    Gennaro Piccolo

    Hi Paul, no it is not.
    Exit terminates the current PowerShell session. Note that this will only happen if you execute your script in powershell.exe, pwsh.exe (PowerShell 7) and not in Visual Studio Code.

    $host.SetShouldExit will terminate the process of the session as well as end with the specific exit code.