Bird
0
0

What will be the output of this code?

medium📝 Command Output Q5 of 15
PowerShell - Working with Objects
What will be the output of this code?
$list1 = 1,2,3,4
$list2 = 3,4,5,6
Compare-Object -ReferenceObject $list1 -DifferenceObject $list2 -ExcludeEqual
A1 <= 2 <= 5 => 6 =>
B3 <= 4 <= 5 => 6 =>
C1 => 2 => 5 <= 6 <=
D3 => 4 => 5 <= 6 <=
Step-by-Step Solution
Solution:
  1. Step 1: Identify unique elements in each list

    1 and 2 are only in list1; 5 and 6 only in list2; 3 and 4 are common.
  2. Step 2: Understand -ExcludeEqual effect

    Common items are excluded; output shows only differences with SideIndicator.
  3. Final Answer:

    1 <= 2 <= 5 => 6 => -> Option A
  4. Quick Check:

    Output shows only unique items with correct SideIndicator [OK]
Quick Trick: Use -ExcludeEqual to hide common items and see only differences [OK]
Common Mistakes:
  • Including common items in output
  • Reversing SideIndicator symbols
  • Confusing which list is Reference or Difference

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes