Bird
0
0

You run this code:

medium📝 Debug Q14 of 15
PowerShell - Working with Objects
You run this code:
$list1 = 'apple', 'banana', 'cherry'
$list2 = 'banana', 'cherry', 'date'
Compare-Object $list1 $list2 -IncludeEqual

But you get an error. What is the likely cause?
AMissing parameter names -ReferenceObject and -DifferenceObject
BThe -IncludeEqual parameter is not valid for Compare-Object
CThe arrays contain strings, which Compare-Object cannot handle
DThe syntax is correct; error is from elsewhere
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter usage

    Compare-Object requires named parameters -ReferenceObject and -DifferenceObject when using switches like -IncludeEqual.
  2. Step 2: Verify syntax validity

    Positional arguments do not bind correctly with -IncludeEqual; missing parameter names cause error.
  3. Final Answer:

    Missing parameter names -ReferenceObject and -DifferenceObject -> Option A
  4. Quick Check:

    Named parameters required with -IncludeEqual [OK]
Quick Trick: Use named parameters with -IncludeEqual to avoid errors [OK]
Common Mistakes:
  • Thinking named parameters are not required with switches
  • Believing -IncludeEqual is invalid
  • Assuming strings cannot be compared

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes