Bird
0
0

What is the issue with this PowerShell pipeline command?

medium📝 Debug Q7 of 15
PowerShell - Cmdlets and Pipeline
What is the issue with this PowerShell pipeline command?
Get-Service | Where-Object Status -eq 'Running' | Sort-Object Name
AThe <code>Get-Service</code> cmdlet does not output objects with a Status property
BThe <code>Sort-Object</code> cmdlet cannot be used after <code>Where-Object</code>
CThe pipeline operator <code>|</code> is missing between commands
DThe <code>Where-Object</code> syntax is incorrect; it requires a script block
Step-by-Step Solution
Solution:
  1. Step 1: Examine the Where-Object usage

    The command uses Where-Object Status -eq 'Running', which is invalid syntax. Where-Object requires a script block like { $_.Status -eq 'Running' }.
  2. Step 2: Validate other parts

    The pipeline operator is correctly used, and Sort-Object can follow Where-Object. Also, Get-Service outputs objects with a Status property.
  3. Final Answer:

    The Where-Object syntax is incorrect; it requires a script block -> Option D
  4. Quick Check:

    Use script block with Where-Object [OK]
Quick Trick: Where-Object needs script block {} [OK]
Common Mistakes:
  • Using property and operator without script block in Where-Object
  • Assuming Sort-Object cannot follow Where-Object
  • Thinking pipeline operator is missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes