[Powershell] List all processes with CPU usage, and filepaths 11-26-2011, 12:14 PM
#1
Screenshot:
![[Image: ibivczPpoRRXgL.png]](http://i.minus.com/ibivczPpoRRXgL.png)
Here's another powershell function i've scripted and put into use. What my script does, is it creates a list of processes and sorts them out by CPU usage, with processes at the top being the most CPU reliant, and processes at the bottom being the least CPU reliant.
Each process returned also returns it's filepath to the location where the process is executed, along with the process name, and process ID.
At the bottom of my script you see a returned value for number of processes currently running, and the time taken to produce the array/list or processes with these statistics.
Enjoy
![[Image: ibivczPpoRRXgL.png]](http://i.minus.com/ibivczPpoRRXgL.png)
Code:
function List_Processes {
write-host; $_date = get-date -format F
$proc_num = 0
$_s = {
write-host "Running Processes Information -" $_date -foregroundcolor "cyan"; write-host
$running = ps | sort-object cpu -descending
$running | %{
foreach ($obj in $_) {
$proc_num++
$num = "[" + $proc_num + "]"
write-host "$num " -nonewline; write-host $obj.Name -foregroundcolor "magenta" -nonewline; write-host " - " -nonewline; write-host "PID:" $obj.ID -foregroundcolor "cyan"
if ($obj.CPU) {
write-host "-- CPU:" $obj.CPU
write-host "-- Location:" $obj.Path
}
write-host
}
}
write-host "----------------------------------------------"
write-host $proc_num "Total Running Processes" -foregroundcolor "cyan"
}
write-host "Script Completion Time:" (measure-command -Expression $_s ).Milliseconds "milliseconds" -foregroundcolor "cyan"; write-host "----------------------------------------------"; write-host
}
List_ProcessesHere's another powershell function i've scripted and put into use. What my script does, is it creates a list of processes and sorts them out by CPU usage, with processes at the top being the most CPU reliant, and processes at the bottom being the least CPU reliant.
Each process returned also returns it's filepath to the location where the process is executed, along with the process name, and process ID.
At the bottom of my script you see a returned value for number of processes currently running, and the time taken to produce the array/list or processes with these statistics.
Enjoy
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)

