Bird
0
0

You want to detect configuration drift by comparing two JSON files representing system settings. Which PowerShell approach correctly detects drift?

hard📝 Application Q15 of 15
PowerShell - Automation Patterns
You want to detect configuration drift by comparing two JSON files representing system settings. Which PowerShell approach correctly detects drift?
AImport both JSON files with Get-Content and compare strings directly
BUse Get-Content with -Raw and compare with -eq operator
CManually open files and visually check for differences
DUse ConvertFrom-Json on both files, then Compare-Object on resulting objects
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON comparison needs

    Comparing JSON as strings can fail due to formatting differences; converting to objects is better.
  2. Step 2: Use ConvertFrom-Json and Compare-Object

    ConvertFrom-Json parses JSON into objects; Compare-Object can then detect differences in properties.
  3. Final Answer:

    Use ConvertFrom-Json on both files, then Compare-Object on resulting objects -> Option D
  4. Quick Check:

    Convert JSON to objects before comparing [OK]
Quick Trick: Parse JSON to objects before comparing [OK]
Common Mistakes:
  • Comparing raw JSON strings directly
  • Using -eq operator for complex objects
  • Relying on manual visual checks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes