NULL Values in Arrays

by Dec 1, 2014

All PowerShell versions

Whenever you assign NULL values to array elements, they will count as array elements, but will not be output (after all, they are NULL aka nothing). This can lead to tough debugging situations, so when the size of an array does not seem to match the content, look for NULL values:

$a = @()
$a += 1
$a += $null
$a += $null
$a += 2
 
1
2
Count: 4 

Twitter This Tip! ReTweet this Tip!