Bird
0
0

You want to list all processes and display their names using $_. Which script correctly uses $_ to achieve this?

hard📝 Application Q8 of 15
PowerShell - Variables and Data Types
You want to list all processes and display their names using $_. Which script correctly uses $_ to achieve this?
AGet-Process | ForEach-Object { Write-Output $Name }
BGet-Process | ForEach-Object { Write-Output $Process.Name }
CGet-Process | ForEach-Object { Write-Output $_ }
DGet-Process | ForEach-Object { Write-Output $_.Name }
Step-by-Step Solution
Solution:
  1. Step 1: Understand $_ usage in pipeline

    $_ refers to the current object, so $_.Name accesses the process name.
  2. Step 2: Evaluate other options

    $Name is undefined, $_ alone outputs full object, and $Process is undefined variable.
  3. Final Answer:

    Get-Process | ForEach-Object { Write-Output $_.Name } -> Option D
  4. Quick Check:

    Use $_.Property to access current pipeline object's property [OK]
Quick Trick: Use $_.Property to get current object's property [OK]
Common Mistakes:
  • Using undefined variables like $Name or $Process
  • Printing whole object instead of property
  • Not using $_ inside ForEach-Object

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes