Powershell: Check variable for null

If your working a lot with parameters and inputs you need to check if variables have the right value and are not “null”.

You can check that (check if $variablename has $null as value):

if (!$variablename) { Write-Host "variable is null" }

And here if you wont to check if $variablename has any value except $null:

if ($variablename) { Write-Host "variable is NOT null" }

 

powershell-null