Skip to main content

NULL Values in Arrays

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
Count: 4 

Twitter This Tip! ReTweet this Tip!

Posted Dec 01 2014, 06:00 AM by ps1


I am the one