# If This, Then That: \`if\`, \`elseif\` and \`else\`

if runs a block of commands only when its test is True, elseif adds another test, else catches everything left, -and, -or and -not join tests together, and exit stops a script early, so a backup copies only when something changed and explains itself when it can't.

![Cheat sheet for the lesson If This, Then That: \`if\`, \`elseif\` and \`else\`: if runs a block of commands only when its test is True, elseif adds another test, else catches everything left, -and, -or and -not join tests together, and exit stops a script early, so a backup copies only when something…](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/64cd341f7a8e401ab76a530337a16b22.webp)

- Category: PowerShell
- Level: Apprentice
- Tags: boolean, comparison-operators, exit-code, if-statement, logical-operators, powershell
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/powershell-if-statements-cheat-sheet
