Converting VBScript's IsNull Function

Definition: Returns a Boolean value that indicates whether an expression contains no valid data (Null).

IsNull

It’s often useful to know whether or not a value is Null; scripters who have worked with Active Directory have often run into problems when trying to do something as seemingly-trivial as echo back the value of a property, at least if that property turns out not to have a value. In Windows PowerShell you can check for a Null value simply by using the -eq comparison operator to compare a variable with the system variable $Null. For example, this command compares $b to $Null, and stores the results of that comparison in $a:

$a = $z -eq $null

When you run this command and then echo back the value of $a you should get the following, assuming, of course, that $z really is Null:

True

If you then use a similar command to determine whether or not $a is Null (i.e., $a -eq $null) you should get back False; that’s because $a isn’t Null.

Return to the VBScript to Windows PowerShell home page