Bird
0
0

How can you combine the pipeline with a ForEach-Object to display the uppercase names of stopped services?

hard📝 Application Q9 of 15
PowerShell - Cmdlets and Pipeline
How can you combine the pipeline with a ForEach-Object to display the uppercase names of stopped services?
AGet-Service | ForEach-Object { $_.Name.ToUpper() } | Where-Object { $_.Status -eq 'Stopped' }
BGet-Service | Where-Object Status -eq 'Stopped' | ForEach-Object { $_.Name.ToUpper() }
CGet-Service | Where-Object { $_.Status -eq 'Stopped' } | ForEach-Object { $_.Name.ToUpper() }
DGet-Service | ForEach-Object { $_.Status -eq 'Stopped' } | Select-Object Name
Step-by-Step Solution
Solution:
  1. Step 1: Filter stopped services first

    Use Where-Object with a script block to filter services with Status 'Stopped'.
  2. Step 2: Use ForEach-Object to transform names

    Pipe filtered results to ForEach-Object to convert each service name to uppercase.
  3. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Stopped' } | ForEach-Object { $_.Name.ToUpper() } -> Option C
  4. Quick Check:

    Filter then transform with ForEach-Object [OK]
Quick Trick: Filter first, then transform with ForEach-Object [OK]
Common Mistakes:
  • Placing ForEach-Object before filtering
  • Omitting script block braces
  • Using incorrect property access

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes