Search notes:

$?

$? is a boolean ($true or $false) that contains the status of the last executed command.
$? can be set by calling Cmdlet.WriteError() or Cmdlet.ThrowTerminatingError().
Because a command is required to evaluate the value of $?, 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

See also

In contrast to $?, $lastExitCode stores the exit code of the last native command or script that was run.
Pipeline chain operators
Other automatic variables

Index