Bird
0
0

Given these two arrays in PowerShell:

medium📝 Command Output Q13 of 15
PowerShell - Automation Patterns
Given these two arrays in PowerShell:
$baseline = @('Setting1', 'Setting2', 'Setting3')
$current = @('Setting1', 'Setting2', 'Setting4')

What will be the output of Compare-Object $baseline $current?
ASetting1 and Setting2 are different
BNo differences found
CSetting3 is in baseline only; Setting4 is in current only
DError: Cannot compare arrays
Step-by-Step Solution
Solution:
  1. Step 1: Compare the two arrays

    Baseline has Setting3; current has Setting4 instead. Setting1 and Setting2 are common.
  2. Step 2: Understand Compare-Object output

    It shows items only in one array with a side indicator. So Setting3 appears only in baseline, Setting4 only in current.
  3. Final Answer:

    Setting3 is in baseline only; Setting4 is in current only -> Option C
  4. Quick Check:

    Compare-Object shows differences = Setting3 is in baseline only; Setting4 is in current only [OK]
Quick Trick: Look for items unique to each list [OK]
Common Mistakes:
  • Assuming no differences when there are
  • Thinking common items show as differences
  • Expecting an error from Compare-Object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes