Bird
0
0

Identify the error in this PowerShell snippet for drift detection:

medium📝 Debug Q6 of 15
PowerShell - Automation Patterns
Identify the error in this PowerShell snippet for drift detection:
$baseline = Get-Content baseline.txt
$current = Get-Content current.txt
Compare-Object -Reference $baseline -Difference $current
AIncorrect parameter names; should be -ReferenceObject and -DifferenceObject
BGet-Content cannot be used to read configuration files
CCompare-Object requires pipeline input, not parameters
DVariables $baseline and $current must be arrays, not strings
Step-by-Step Solution
Solution:
  1. Step 1: Check Compare-Object parameter names

    The correct parameters are -ReferenceObject and -DifferenceObject, not -Reference or -Difference.
  2. Step 2: Validate other parts

    Get-Content returns arrays of lines, suitable for comparison; pipeline input is optional.
  3. Final Answer:

    Incorrect parameter names; should be -ReferenceObject and -DifferenceObject -> Option A
  4. Quick Check:

    Parameter names must be exact = D [OK]
Quick Trick: Use full parameter names: -ReferenceObject and -DifferenceObject [OK]
Common Mistakes:
  • Using shortened or incorrect parameter names
  • Assuming Get-Content output is invalid
  • Thinking pipeline is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes