Bird
0
0

Why does Compare-Object sometimes show duplicate entries when comparing lists with repeated values?

hard📝 Conceptual Q10 of 15
PowerShell - Working with Objects
Why does Compare-Object sometimes show duplicate entries when comparing lists with repeated values?
ABecause it ignores duplicates and shows only unique differences
BBecause it merges duplicates automatically in output
CBecause it compares each occurrence individually, not just unique values
DBecause it only compares the first occurrence of each value
Step-by-Step Solution
Solution:
  1. Step 1: Understand how Compare-Object treats duplicates

    It compares each item occurrence, so duplicates in inputs are compared separately.
  2. Step 2: Reason about output duplicates

    Duplicates appear if one list has more occurrences than the other, showing multiple difference entries.
  3. Final Answer:

    Because it compares each occurrence individually, not just unique values -> Option C
  4. Quick Check:

    Duplicates appear due to per-occurrence comparison [OK]
Quick Trick: Compare-Object compares each item occurrence, causing duplicates [OK]
Common Mistakes:
  • Thinking duplicates are merged automatically
  • Assuming only unique values are compared
  • Believing duplicates are ignored

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes