PowerShell: True/False (boolean)

By Xah Lee. Date: . Last updated: .

Whenever you need boolean, use $true or $false. They are Automatic Variables.

If you just type “True” in PowerShell, it's a error, because its invalid command or expression. Nor is it a valid literal expression.

PowerShell True/False Interpretation
ValueValue in Boolean Context
$trueTrue
Nonzero numberTrue
Nonempty stringTrue
Nonempty arrayTrue
Hashtable (empty or not)True
$falseFalse
$nullFalse
ZeroFalse
Empty stringFalse
Empty arrayFalse

Logical Operators

a -and b
True when both sides are true.
a -or b
True when at least one side is true.
a -xor b
“exclusive or”. True when only one side is true.
-not a
Reverse true/false.
! a
Same as -not

PowerShell

Practical How-To

PowerShell in Depth

Programing PowerShell

Script Examples