Bird
0
0

You want to automate a task that lists all services, filters only running ones, and sorts them by name. Which combination of cmdlets achieves this?

hard📝 Application Q15 of 15
PowerShell - Cmdlets and Pipeline
You want to automate a task that lists all services, filters only running ones, and sorts them by name. Which combination of cmdlets achieves this?
AGet-Service -Status Running | Sort-Object -Property Status
BGet-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name
CGet-Process | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name
DGet-Service | Sort-Object Status | Where-Object { $_.Status -eq 'Running' }
Step-by-Step Solution
Solution:
  1. Step 1: Identify cmdlet to get services

    Get-Service retrieves all services.
  2. Step 2: Filter running services correctly

    Where-Object filters services where Status equals 'Running'.
  3. Step 3: Sort filtered services by name

    Sort-Object sorts the filtered list by the Name property.
  4. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name -> Option B
  5. Quick Check:

    Filter then sort = Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name [OK]
Quick Trick: Filter first, then sort for correct results [OK]
Common Mistakes:
  • Filtering after sorting loses efficiency
  • Using Get-Process instead of Get-Service
  • Sorting by wrong property

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes