Boolean literals in PowerShell

$true and $false.

Those are constants, though. There are no language-level literals for Booleans.

Depending on where you need them, you can also use anything that coerces to a Boolean value, if the type has to be Boolean, e.g., in method calls that require Boolean (and have no conflicting overload), or conditional statements. Most non-null objects are true, for example. null, empty strings, empty arrays and the number 0 are false.

Leave a Comment