WScript.Quit( Value ) does not always match the error code environment variable %errorlevel% in the command processor ( batch file processing ) environment.

In the windows scripting host environment, the WScript.Quit method can be used to return an exit code to a calling process. In 99.9% of the cases, the value set with the WSCript.Quit method will be returned as expected. If you are running your script code in a command window, the value usually comes back in…

1

Using the global error collection stored in the $Error variable to retrieve detailed error information in a powershell script

I was recently working with a developer who wanted to know if there is a way to get the error when they call the Invoke-Expression cmdlet. He was using the $LastExitCode to determine if it succeeded or not. Unfortunately, the $LastExitCode was not returning the error he was expecting. A better way of checking for…