Almost all applications and utilities will set an exit code when they complete/terminate.
In the CMD shell the exit code is made available via the %errorlevel% variable.
The exit codes that are set will vary according to the application/utility, in general a code of 0 (false) will indicate successful completion.
The exit codes set by resource kit utilities are not always consistent, they may vary between machines with different Service packs/Resource kit updates applied.
Some utilities will return negative numbers as an exit code.
You should never attempt to write to the %errorlevel% variable directly. When writing a batch file, you can make it return a non-zero exit code by using the EXIT command.
In PowerShell $? contains True if last operation succeeded and False otherwise.
The exit code of the last Win32 executable execution is stored in the automatic variable $LASTEXITCODE
To read exit codes (other than 0 or 1) launch the PowerShell script and return the $LASTEXITCODE in a single line like this:
powershell.exe -noprofile C:\scripts\script.ps1; exit $LASTEXITCODE
“I’d rather wake up in the middle of nowhere than in any city on earth” ~ Steve McQueen
Robocopy exit codes