PowerShell: True, False (boolean)

By Xah Lee. Date: . Last updated: .

True and False Representation

PowerShell $true $false

Dotnet True False

What Values Are True or False

True Values
ValueValue in Boolean Context
$true$true
Nonzero number$true
Nonempty String$true
Nonempty Array$true
Hashtable (empty or not)$true
False Values
ValueValue in Boolean Context
$false$false
$null$false
Zero$false
Empty String$false
Empty Array$false

Force to Boolean (Casting)

$x = 3
[bool] $x
# True

$x = ""
[bool] $x
# False

PowerShell. Boolean Related