PowerShell: True/False

By Xah Lee. Date: .

Whenever you need boolean, use $true or $false. They are automatic variables. [see PowerShell: Predefined 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

PowerShell

How-to

Advanced

Script Examples