# Did It Work? \`$?\`, \`$LASTEXITCODE\`, \`&&\` and \`||\`

$? says whether the last command worked, $LASTEXITCODE holds the number a program ended with (0 when it worked), && runs the next command only if the last one worked, and || runs it only if the last one failed.

![Cheat sheet for the lesson Did It Work? \`$?\`, \`$LASTEXITCODE\`, \`&&\` and \`||\`: $? says whether the last command worked, $LASTEXITCODE holds the number a program ended with (0 when it worked), && runs the next command only if the last one worked, and || runs it only if the last one failed.](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/a83c926943a74172876f742dbd0bb6c7.webp)

- Category: PowerShell
- Level: Apprentice
- Tags: automatic-variable, boolean, exit-code, pipeline-chain-operator, powershell
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/powershell-did-it-work-cheat-sheet
