Search notes:

PowerShell: The automatic variable $NULL

$null is an automatic variable. It is the only instance of the null type.
$null is also referred to as null value.
The value of a PowerShell variable that was not assigned a value (yet) is $null. The value of $null itself is the C# value null.
$null can be assigned any value; yet, the value of $null remains unchanged:
PS C:\> $null = mkdir temp-dir
PS C:\> $null
Assigning a value of an expression to $null is typically used to hide the returned result on the console. In order to be more explicit about this intention, some prefer to write mkdir temp-dir | out-null instead.
$null has a count property whose value is 0:
PS C:\> $null.count
0

Checking for a null value

Unlike the null value in SQL, $null can be compared to itself. Thus, comparison operators such as -eq can be used to check if a variable is $null:
if ($val -eq $null) {
  'val is null'
} else {
  'val is not null'
}

See also

$null is implemented by the System.Management.Automation.NullVariable class.
Other automatic variables
The ValidateNotNull(), allowNull() and validateNotNullOrEmpty() attributes for parameters.

Index