$?
, its value must be checked right after executing a command: PS C:\Users\Rene> no-such-command no-such-command: The term 'no-such-command' is not recognized as a name of a cmdlet, function, script file, or executable program … PS C:\Users\Rene> $? False PS C:\Users\Rene> $? True
$?
, $lastExitCode
stores the exit code of the last native command or script that was run.