Search code examples
powershell

Listing processes by CPU usage percentage in powershell


How does one lists the processes using CPU > 1% by piping the output from Get-Process to Where-Object?

Complete beginner to powershell all i can think is something like this

Get-Process | Where-Object { CPU_Usage -gt 1% }

Solution

  • If you want CPU percentage, you can use Get-Counter to get the performance counter and Get-Counter can be run for all processes. So, to list processes that use greater than say 5% of CPU use:

    (Get-Counter '\Process(*)\% Processor Time').CounterSamples | Where-Object {$_.CookedValue -gt 5}
    

    This will list the processes that was using >5% of CPU at the instance the sample was taken. Hope this helps!