Bird
0
0

Identify the issue in this PowerShell script snippet:

medium📝 Debug Q6 of 15
PowerShell - Automation Patterns
Identify the issue in this PowerShell script snippet:
$services = Get-Service | Where-Object { Status -eq 'Stopped' }; $services | Export-Csv -Path 'stopped.csv' -NoTypeInformation
AThe script uses 'Status' without the pipeline variable '$_' inside Where-Object
BExport-Csv cannot export service objects
CThe file path 'stopped.csv' is invalid without a full path
DNo error; the script runs correctly
Step-by-Step Solution
Solution:
  1. Step 1: Check Where-Object syntax

    Inside script blocks, properties must be referenced as $_.Property.
  2. Step 2: Identify error

    Using 'Status' alone causes an undefined variable error.
  3. Final Answer:

    The script uses 'Status' without the pipeline variable '$_' inside Where-Object -> Option A
  4. Quick Check:

    Use $_.Status in Where-Object filters [OK]
Quick Trick: Use $_.Property inside Where-Object script blocks [OK]
Common Mistakes:
  • Omitting $_ when referencing object properties in filters
  • Assuming Export-Csv requires full file paths always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes