2

just when I thought I knew PowerShell, I'm wondering what's going on here. Compare-Object works for both of these examples, and the second example will return the differences if I don't check for $null, but I'm having the worst time doing a simple comparison. Why does the second example not return False?

(compare-object @(1,2,3)  @(1,2,3)) -eq $null

True

(compare-object @(1,2,3)  @(1,2,3,4,5,6)) -eq $null

(nothing returned) - I expect to see False

Dave Markle
  • 95,573
  • 20
  • 147
  • 170

1 Answers1

2

This is because the result is an array, you should check for the count to determine whether there is content:

((compare-object @(1,2,3)  @(1,2,3)) | measure).count -gt 0

and

((compare-object @(1,2,3)  @(1,2,3, 4, 5, 6)) | measure).count -gt 0
Martin Brandl
  • 56,134
  • 13
  • 133
  • 172
  • 2
    I guess that's sort of my issue with this - that I need to make the call to Measure-Object because in the first example, the return value is *not* an array, it's just $null. I see now that my issue is with the fun way that PS compares arrays to $null. – Dave Markle Nov 29 '16 at 17:15