%ERRORLEVEL% and PowerShell

in case you are writing PowerShell scripts and want to monitor the success of them using %ERRORLEVEL%, you should be aware that Exit(##) in your PS1 scripts will not effect the error level you read coz you are not on the same context as PowerShell.

The solution (thanks to Dani) is to use:

$host.SetShouldExit(int exitCode)
exit

* I must say that for me if looks like a bug that I need to alter my code so that other can read my exit code.

This should do the the job.

%ERRORLEVEL% and PowerShell %ERRORLEVEL% and PowerShell Reviewed by Ran Davidovitz on 2:07 AM Rating: 5

No comments:

Powered by Blogger.