Skip to content

Latest commit

 

History

History

Exit-code-5-with-File-1-with-Command

Exit code 5 with File, 1 with Command

If PowerShell.exe invokes a script which exists with exit 5 then the exit code depends on how the script is invoked. If it is invoked with the parameter File then the exit code is 5. If it is invoked with the parameter Command then the exit code is 1.

As far as File returns the actual exit code, it looks like that using just File and avoiding Command solves the issue, the actual exit code will be obtained. With File there is another issue, see Exit-code-0-with-File-script-error.

Workaround

In order to get the actual exit code on invoking a script with Command an extra statement exit $LastExitCode can be used.

Scripts