Get Top 5 CPU Consuming Processes {PowerShell} - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Computer Support Topics (https://www.supportforums.net/forumdisplay.php?fid=4) +---- Forum: Microsoft Support (https://www.supportforums.net/forumdisplay.php?fid=5) +---- Thread: Get Top 5 CPU Consuming Processes {PowerShell} (/showthread.php?tid=21602) Pages:
1
2
|
Get Top 5 CPU Consuming Processes {PowerShell} - AceInfinity - 08-20-2011 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 Preview: RE: Get Top 5 CPU Consuming Processes {PowerShell} - Kom - 08-20-2011 Looks nice, I have a Rainmeter app that does this for me though (Can't remember the name or what skin it's from though >.> lol) Quite useful if you want to know what's using what =p RE: Get Top 5 CPU Consuming Processes {PowerShell} - AceInfinity - 08-20-2011 Rainmeter is nice for a quick display, and this is very simple for a powershell script though. Powershell is far more sophisticated than Rainmeter no doubt, but I wasn't sure what else I could do with processes. I could kill all the top 5 processes if I wanted using this script I created, but you probably don't want to do that lol. I have another I created before this to kill and restart explorer.exe: Code: $proc = Get-Process One thing about powershell is that you can send in full command outputs as variables to decide what the next command will do with it, you can split functions, and join them too. RE: Get Top 5 CPU Consuming Processes {PowerShell} - Kom - 08-20-2011 Yea, don't think you exactly want to kill the top 5 users lmao, Could cause some issues =p RE: Get Top 5 CPU Consuming Processes {PowerShell} - 【 ¶ÑÇƦ€Ƿ¦ßŁΞ 】 - 08-20-2011 But we can check the same from windows task manager by pressing CTRL+ALT+DELETE ? right RE: Get Top 5 CPU Consuming Processes {PowerShell} - Kom - 08-20-2011 (08-20-2011, 03:11 PM)【 ¶ÑÇƦ€Ƿ¦ßŁΞ 】 Wrote: But we can check the same from windows task manager by pressing CTRL+ALT+DELETE ? right I would say this is a more detailed thing, but that's my opinion. I think a nice edit to this would be to put all the processes not just the top 5 with the amount their using and the location of the file... Would be good over all but also nice for an anti-malware addition to it =p RE: Get Top 5 CPU Consuming Processes {PowerShell} - AceInfinity - 08-20-2011 (08-20-2011, 03:14 PM)Kom Wrote: I would say this is a more detailed thing, but that's my opinion. Just remove this bit then: Code: If ($num -gt $Total) { It already has a built in function for it though: RE: Get Top 5 CPU Consuming Processes {PowerShell} - Kom - 08-20-2011 Yea but it doesn't show the location of the file. Would be nice if it did (I already knew to break the loop lol was just trying to explain it) RE: Get Top 5 CPU Consuming Processes {PowerShell} - AceInfinity - 08-20-2011 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}, ` Try this: Code: # Created by Ace - Copyright 2011 TechLifeForum.net 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 ** 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 RE: Get Top 5 CPU Consuming Processes {PowerShell} - WhosYourDaddy - 08-21-2011 (08-20-2011, 03:14 PM)Kom Wrote: I would say this is a more detailed thing, but that's my opinion. It's definitely more detailed, and I like it. Keep up the good work, buddy. |