Booleans

Boolean (true or false) variables are most commonly initialized to their literal values of $true and $false. When it evaluates them as part of a Boolean expression (i.e., an “if” statement,) though, PowerShell maps results into a suitable Boolean representation.

Windows PowerShell Boolean interpretations

Result

Boolean representation

$true

True

$false

False

$null

False

Nonzero number

True

Zero

False

Nonempty string

True

Empty string

False

Nonempty array

True

Empty array

False

Hashtable (either empty or not)

True

Get Windows PowerShell Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.