There are several ways you can check if a string is null or empty in PowerShell, the best way is to use a string method IsNullOrEmpty
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$var1 = $null $var2 = '' $var3 = "notnull" [string]::IsNullOrEmpty($var1) ## returns true [string]::IsNullOrEmpty($var2) ## returns true [string]::IsNullOrEmpty($var3) ## returns false if ([string]::IsNullOrWhitespace($var1)) { echo "action on null" } else { echo "action on not null" } |