PowerShell stores this in a variable:

PS > $lastExitCode
0