$LastExitCode
is the return code of native applications. $?
just returns True
or False
depending on whether the last command (cmdlet or native) exited without error or not.
For cmdlets failure usually means an exception, for native applications it's a non-zero exit code:
PS> cmd /c "exit 5"
PS> $?
False
PS> cmd /c "exit 0"
PS> $?
True
Cancelling a cmdlet with Ctrl+C will also count as failure; for native applications it depends on what exit code they set.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…