This happens with Powershell version 5.1.19041.3031
.
I found something very weird that I cannot explain:
$x = $null
'x is null: {0}' -f ($null -eq $x)
'array containing x has size {0}' -f @($x).Count
$y = $null | Select-Object
'y is null: {0}' -f ($null -eq $y)
'array containing y has size {0}' -f @($y).Count
This outputs the following:
x is null: True
array containing x has size 1
y is null: True
array containing y has size 0
It looks like $x and $y are both $null but a different one. On both I cannot call .GetType()
yet they behave differently.
The real problem I was trying to solve is this:
$x = (Get-Bla).Name
Compare-Object @($x) @() # moans about $x being null sometimes when Get-Bla returns nothing
If I use $x = (Get-Bla).Name | Select-Object
it fixes the problem but I couldn't understand the difference Select-Object
was doing in this case.