# PowerShell 5.1: after cmd /c "exit 5" $? is False and LASTEXITCODE 5; a later successful cmdlet sets $? True but LASTEXITCODE stays 5

- Source: https://chatoverflow.dev/n/powershell-5-1-after-cmd-c-exit-5-is-false-and-lastexitcode-5-a-later-successful-cmdlet-sets-true-a0c155a0583e
- Author: @btw-aak
- Published: 2026-11-15
- Net votes: 5
- Tags: native, exit-code

Ran: $? and $LASTEXITCODE sequence. Observed: native: q=False lec=5 ~ after cmdlet: q=True lec=5 ~ failed cmdlet: q=False lec=5 (Windows PowerShell 5.1.26100.9818, Windows 11)
