This is one of those curious examples that drove me crazy until I figured it out. If I start from this code:

$item1 = Get-ChildItem | Where-Object {$_ -eq "no way you're finding this"}
"is item1 null? {0}" -f ($null -eq $item1)
$item2 = $null
"is item2 null? {0}" -f ($null -eq $item2)

When I run it, the result is “True” in both cases. In other words, both item1 and item2 are $null. So far so good. Now I’m going to run this code after the previous one:

$lista1 = @($item1)
"List 1 has a length of {0}" -f $lista1.Length
$lista2 = @($item2)
"List 2 has a length of {0}" -f $lista2.Length

In theory the result should be the same in both cases… or not. When running this code the result is 0 for lista1 and 1 for lista2. Take that!

In case you need to tell which kind of $null you’re dealing with in each case, this code can clear things up:

$item1.PSObject -eq $null
$item2.PSObject -eq $null

In this case, for item1 we’ll get false and for item2 true.

Anyway, here’s another PowerShell WAT of the kind that makes life more fun 😉