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

0

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

1 Comment

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.