$lastExitCode is the return value of the most recently executed executable (on Windows: .exe) or PowerShell script. $lastExitCode is Int32. $? is a Boolean which indicates the succuess or failure of the last command, regardless if it was an executable or a PowerShell cmdlet or function. cmd.exe variable %errorlevel%. profile.ps has the following piece of code which uses the prompt to write the last exit code in red if it is different from 0: function prompt {
if ($lastExitCode) {
$error = "$([char]0x1b)[91mlastExitCode = $lastExitCode$([char]0x1b)[0m`n"
}
else {
$error = ''
}
…
$prompt = "…"
"$error$prompt"