Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Top 5 CPU Consuming Processes {PowerShell}
#9
Hmm... That's not a bad idea, I could put together something like that. I could Pipeline each object instance out and use the System.Diagnostics object with powershell to get the paths.
Here's a quick demo testfile I put together which saves the output of a process list with filepath's to a text file in your C:\ drive called "Output_Proc_List.txt"

Code:
$Process = @{Expression={$_.Name};Label="Process Name";width=25}, `
@{Expression={$_.Path};Label="Filepath"}

$Proc = Get-Process | Format-Table $Process | Out-File -Filepath C:\Output_Proc_List.txt

Try this:
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 $objItm.Path -foregroundcolor "white"
    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

that will display the top 5 CPU consuming processes with their filepath, for all of them, just remove that loop breaking block of code I have in there.



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

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

write-host
foreach ($objItm in $Proc) {
    write-host "$num) " -foregroundcolor "white" -nonewline; write-host $objItm.ProcessName -foregroundcolor "magenta" -nonewline;
    If (!($objItm.CPU -eq $null)) {
        write-host " - CPU:"$objItm.CPU -foregroundcolor "white"
        } else {
            write-host " - CPU: " -foregroundcolor "white" -nonewline; write-host "N/A" -foregroundcolor "darkgray"
        }
    If (!($objItm.Path -eq $null)) {
        write-host $objItm.Path -foregroundcolor "cyan"
    } else {
        write-host "** [No filepath to this process]" -foregroundcolor "darkgray"
    }
    write-host "# ID:" $objItm.ID -foregroundcolor "white"
    write-host
    $num += 1
}

write-host
write-host -------------------------------------------------- -foregroundcolor "cyan"
write-host ">" You have ($num - 1) currently running processes... -foregroundcolor "cyan"
write-host -------------------------------------------------- -foregroundcolor "cyan"
write-host

[Image: ibYCN7cMZ.png]

** Note: If you use this instead, it will sort each by process name alphabetically after the ordered process numbered list
Code:
$Proc = Get-Process | Sort-Object ProcessName
Reply


Messages In This Thread
RE: Get Top 5 CPU Consuming Processes {PowerShell} - by AceInfinity - 08-20-2011, 03:48 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: 4 Guest(s)