PowerShell: True, False (boolean)
By Xah Lee. Date: . Last updated: .
True and False Representation
PowerShell $true $false
$true
or $false
are values in PowerShell to represent true and false.
- They are Automatic Variables.
Dotnet True False
- PowerShell is hosted in dotnet.
- In dotnet, boolean values are represented by
True
and False
. These are not valid in PowerShell, but PowerShell may print result using them.
What Values Are True or False
True Values
Value | Value in Boolean Context |
$true | $true |
Nonzero number | $true |
Nonempty String | $true |
Nonempty Array | $true |
Hashtable (empty or not) | $true |
False Values
Value | Value in Boolean Context |
$false | $false |
$null | $false |
Zero | $false |
Empty String | $false |
Empty Array | $false |
Force to Boolean (Casting)
$x = 3
[bool] $x
$x = ""
[bool] $x
PowerShell. Boolean Related