Bird
0
0

Which of the following is the correct PowerShell pipeline syntax to get services with the status 'Stopped'?

easy📝 Syntax Q3 of 15
PowerShell - Cmdlets and Pipeline
Which of the following is the correct PowerShell pipeline syntax to get services with the status 'Stopped'?
AGet-Service | Where-Object Status == 'Stopped'
BGet-Service | Where-Object { $_.Status = 'Stopped' }
CGet-Service | Where-Object { $_.Status -eq 'Stopped' }
DGet-Service | Where-Object { Status -eq 'Stopped' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand correct comparison operator

    PowerShell uses -eq for equality comparison inside script blocks.
  2. Step 2: Correct syntax for property access

    Inside Where-Object, use $_ to reference the current object and its properties.
  3. Step 3: Evaluate options

    Get-Service | Where-Object { $_.Status -eq 'Stopped' } correctly uses $_ and -eq. Get-Service | Where-Object { $_.Status = 'Stopped' } uses assignment = instead of comparison. Get-Service | Where-Object Status == 'Stopped' uses invalid syntax without script block. Get-Service | Where-Object { Status -eq 'Stopped' } omits $_ which is required.
  4. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Stopped' } -> Option C
  5. Quick Check:

    Use -eq and $_ inside script block [OK]
Quick Trick: Use $_.Property -eq 'value' inside Where-Object [OK]
Common Mistakes:
  • Using = instead of -eq for comparison
  • Omitting $_ when accessing object properties
  • Not enclosing condition in script block {}

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes