not null check in powershell variable 1

not null check in powershell variable

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

Here is what the above code is Doing:
1. It’s creating a variable called $variablename and assigning it a value of null.
2. It’s checking to see if the variable is null.
3. It’s checking to see if the variable is not null.

The first check will return true because the variable is null. The second check will return false because the variable is null.

Similar Posts