Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Top 5 CPU Consuming Processes {PowerShell}
#1
Here's another code I wrote lately in PowerShell scripting that will sort out a list of processes, and take that list sorting each object by CPU consumption in reverse order. From that sorted list it grabs the first 5 Processes in the list using a loop and gets the values of each object ProcessID and ProcessName. I've put the number of Top Processes to display in a variable ($Total) so that it's easy for you to choose how many you want to display with this script.

Code:
# Created by Ace - Copyright 2011 TechLifeForum.net

$Proc = Get-Process | Sort-Object CPU -Descending
$Total = 5
$num = 1

write-host
foreach ($objItm in $Proc) {
    If ($num -gt $Total) {
        break #break the loop
    }
    write-host "$num) " -foregroundcolor "white" -nonewline; write-host $objItm.ProcessName -foregroundcolor "cyan" -nonewline; write-host " - CPU:"$objItm.CPU
    write-host "# ID:" $objItm.ID -foregroundcolor "white"
    write-host
    $num += 1
}

write-host
write-host ------------------------------------------------------------------------ -foregroundcolor "cyan"
write-host These are your top $Total CPU consuming processes... -foregroundcolor "cyan"
write-host ------------------------------------------------------------------------ -foregroundcolor "cyan"
write-host

Preview:
[Image: ieaeFxEA1.png]
Reply


Messages In This Thread
Get Top 5 CPU Consuming Processes {PowerShell} - by AceInfinity - 08-20-2011, 02:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [GUI PowerShell] Get_UserACC - Get All User Accounts Info from WMI (Advanced Script) AceInfinity 4 2,312 01-06-2012, 05:22 PM
Last Post: AceInfinity
  Powershell Services Script AceInfinity 2 1,611 08-17-2011, 10:48 PM
Last Post: AceInfinity
  PowerShell Hotfix List Script - Created by Ace AceInfinity 4 2,187 08-16-2011, 12:09 PM
Last Post: AceInfinity
  ╩ Core Processes Thread ╩ Reality 2 1,176 07-28-2010, 03:10 PM
Last Post: Reality

Forum Jump:


Users browsing this thread: 1 Guest(s)