Bob Bob - 10 months ago 64
PowerShell Question

Powershell - What does if($variable) test for?

In Powershell, what does

test for? Is this testing if the variable is set, is null, is true, or something else?


It tests whether the variable is true or whether a non-Boolean variable can be coalesced to true. For example, each of these return false:

$var #uninitialized
$var = ""
$var = $false
$var = 0

Each of these return true:

$var = "something"
$var = $true
$var = 1 #or any non-zero number