Bird
0
0

What will be the output of this PowerShell snippet?

medium📝 Predict Output Q4 of 15
PowerShell - Automation Patterns
What will be the output of this PowerShell snippet?
$baseline = @{Setting1='On'; Setting2='Off'}
$current = @{Setting1='On'; Setting2='On'}
Compare-Object -ReferenceObject $baseline -DifferenceObject $current -Property Setting2
ANo output because both have Setting1 'On'
BShows Setting2 difference with SideIndicator showing which object has which value
CError because hashtables cannot be compared
DOutputs all settings without filtering
Step-by-Step Solution
Solution:
  1. Step 1: Understand Compare-Object with hashtables and -Property

    It compares the specified property (Setting2) between baseline and current hashtables.
  2. Step 2: Analyze the difference in Setting2 values

    Baseline has 'Off', current has 'On' for Setting2, so output shows this difference with SideIndicator.
  3. Final Answer:

    Shows Setting2 difference with SideIndicator showing which object has which value -> Option B
  4. Quick Check:

    Compare-Object outputs differences with SideIndicator = B [OK]
Quick Trick: Compare-Object shows differences with SideIndicator arrows [OK]
Common Mistakes:
  • Assuming no output if one property matches
  • Thinking hashtables can't be compared
  • Expecting all properties without filtering

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes