I'm writing Powershell (v5.1) trying to ouptut a PSCustomObject, and then a few lines later output a hashtable. However it appears that outputting the PSCustomObject is preventing the Hashtable from outputting properly. Why does this happen?
This is a minimal example:
$foobar = [PSCustomObject]@{foo = 'bar'}
Write-Output $foobar # Comment out this line and it outputs wizwam
$wizwam = @{'wiz' = 'wam' }
Write-Output $wizwam
This is the output:
foo
---
bar
But I would have expected this output:
foo
---
bar
Name Value
---- -----
wiz wam
Interestingly, if I comment out the second line (Write-Output $foobar
), then it does output WizWam properly:
Name Value
---- -----
wiz wam
Also, if I swap the order of foobar and wizwam:
$wizwam = @{'wiz' = 'wam' }
Write-Output $wizwam
$foobar = [PSCustomObject]@{foo = 'bar'}
Write-Output $foobar
Then it outputs both wizwam and foobar as expected:
Name Value
---- -----
wiz wam
foo : bar
What is going on?