Bird
0
0

Which command correctly lists all running services and saves their display names to a text file using cmdlets as building blocks?

hard📝 Application Q8 of 15
PowerShell - Cmdlets and Pipeline
Which command correctly lists all running services and saves their display names to a text file using cmdlets as building blocks?
AGet-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object -ExpandProperty DisplayName | Out-File services.txt
BGet-Service -Status Running > services.txt
CGet-Service | Select-Object DisplayName | Out-File services.txt
DGet-Service | Where-Object Status = 'Running' | Out-File services.txt
Step-by-Step Solution
Solution:
  1. Step 1: Filter running services

    Use Where-Object with '$_.' to filter services where Status equals 'Running'.
  2. Step 2: Extract display names

    Select-Object with -ExpandProperty extracts just the DisplayName strings.
  3. Step 3: Output to file

    Out-File writes the output to 'services.txt'.
  4. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Running' } | Select-Object -ExpandProperty DisplayName | Out-File services.txt -> Option A
  5. Quick Check:

    Filter, select property, then output to file [OK]
Quick Trick: Filter, expand property, then output to file [OK]
Common Mistakes:
  • Using incorrect parameter syntax
  • Not expanding property before output
  • Using '=' instead of '-eq' in Where-Object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes