Listing CPU Intensive Processes in PowerShell

This sample defines a PowerShell function that lists CPU intensive processes running on a machine. If you call the function without any parameters it will list the top 5 CPU intensive processes. However, you can also pass to the function the number of items you wanted returned along with a name mask for matching processes.

  Function Get-ExpensiveProcesses([int] $processCount = 5,[string] $optionalMask = "*") {
    Get-Process $optionalMask | Sort-Object CPU -Descending | Select-Object -first $processCount


Examples of using this sample:

  C:\Windows\system32> ListExpensiveProcesses
  C:\Windows\system32> ListExpensiveProcesses 10
  C:\Windows\system32> ListExpensiveProcesses 10 "*svchost*"


Tip: Get-Process has a "-ComputerName" switch which allows you to list processes from another machine. You could modify this script to also take a machine name parameter.

© 2024