Bird
0
0

Which of the following is the correct syntax to filter processes with CPU usage greater than 100 using Where-Object?

easy📝 Syntax Q12 of 15
PowerShell - Cmdlets and Pipeline
Which of the following is the correct syntax to filter processes with CPU usage greater than 100 using Where-Object?
AGet-Process | Where-Object { CPU > 100 }
BGet-Process | Where-Object { $_.CPU -gt 100 }
CGet-Process | Where-Object CPU -gt 100
DGet-Process | Where-Object CPU > 100
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct use of script block and $_ variable

    Where-Object requires a script block with curly braces and uses $_ to refer to the current object.
  2. Step 2: Check each option's syntax

    Get-Process | Where-Object { $_.CPU -gt 100 } correctly uses { $_.CPU -gt 100 }. Versions without the script block braces {} are incorrect. The version with { CPU > 100 } misses $_ before CPU.
  3. Final Answer:

    Get-Process | Where-Object { $_.CPU -gt 100 } -> Option B
  4. Quick Check:

    { $_.Property -gt value } syntax = D [OK]
Quick Trick: Always use { $_.Property -operator value } inside Where-Object [OK]
Common Mistakes:
  • Omitting curly braces {}
  • Not using $_ to reference current object
  • Writing condition outside script block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes