Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Boolean (true or false) variables are most commonly initialized to their literal values of $true and $false. When it evaluates them as part of a Boolean expression (i.e., an “if” statement,) though, PowerShell maps results into a suitable Boolean representation.
| Windows PowerShell Boolean interpretations | |
|---|---|
| Result | Boolean representation |
| $true | True |
| $false | False |
| $null | False |
| Nonzero number | True |
| Zero | False |
| Nonempty string | True |
| Empty string | False |
| Nonempty array | True |
| Empty array | False |
| Hashtable (either empty or not) | True |