Fetch top 10 processes utilizing high CPU as shown in task manager

%3CLINGO-SUB%20id%3D%22lingo-sub-1239627%22%20slang%3D%22en-US%22%3EFetch%20top%2010%20processes%20utilizing%20high%20CPU%20as%20shown%20in%20task%20manager%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1239627%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3EI%20have%20requirement%20where%20i%20have%20to%20fetch%20top%2010%20processes%20utilizing%20high%20cpu%20as%20shown%20in%20task%20manager.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20guide%20me%20how%20to%20do%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1239627%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Eprocesses%20for%20high%20cpu%20load%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1240342%22%20slang%3D%22en-US%22%3ERe%3A%20Fetch%20top%2010%20processes%20utilizing%20high%20CPU%20as%20shown%20in%20task%20manager%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1240342%22%20slang%3D%22en-US%22%3E%3CP%3EHey%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F587514%22%20target%3D%22_blank%22%3E%40Prashantsahu%3C%2FA%3E%2C%26nbsp%3Bare%20you%20actually%20needing%20the%20%22percentage%22%20values%20like%20shown%20in%20the%20Task%20Manager%20(it%20is%20possible%2C%20just%20more%20work)%2C%20or%20is%20it%20enough%20to%20still%20know%20the%20top%2010%20processes%20putting%20strain%20on%20the%20CPU%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EGive%20this%20a%20go%20and%20see%20how%20you%20get%20on%2C%20start%20with%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmicrosoft.powershell.management%2Fget-process%3Fview%3Dpowershell-7%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3EGet-Process%3C%2FA%3E%26nbsp%3Bwhich%20returns%20all%20of%20the%20processes%20on%20the%20system.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3EGet-Process%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENotice%20that%20there%20is%20a%20'CPU(s)'%20property%20in%20the%20output%2C%20that's%20the%20%22%3CSPAN%3Eamount%20of%20processor%20time%20that%20the%20process%20has%20used%20on%20all%20processors%2C%20in%20seconds%22.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ENext%2C%20you'll%20want%20to%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmicrosoft.powershell.utility%2Fsort-object%3Fview%3Dpowershell-7%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESort-Object%3C%2FA%3E%20to%20sort%20the%20list%20of%20processes%20using%20the%20most%20processor%20time.%20You'll%20note%20however%20that%20you%20can't%20sort%20by%20'CPU(s)'%20as%20there's%20some%20trickery%20going%20on%20behind%20the%20scenes%2C%20but%20you%20can%20sort%20by%20'CPU'%20and%20you'll%20also%20want%20to%20make%20this%20list%20descending%20so%20that%20the%20largest%20numbers%20are%20at%20the%20top.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%3ESort-Object%20-Property%20CPU%20-%3C!--StartFragment%20--%3E%3C%2FSPAN%3E%3CSPAN%3EDescending%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EFinally%2C%20you%20only%20want%20the%20top%2010%2C%20so%20use%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fpowershell%2Fmodule%2Fmicrosoft.powershell.utility%2Fselect-object%3Fview%3Dpowershell-7%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3ESelect-Object%3C%2FA%3E%20and%20specify%20that%20you%20only%20want%20the%20first%2010%20objects.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%3ESelect-Object%20-First%2010%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EPut%20that%20all%20together%20and%20you%20get%20something%20like%20this%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3C!--StartFragment%20--%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%3EGet-Process%3C%2FSPAN%3E%3CSPAN%3E%20%7C%20%3C%2FSPAN%3E%3CSPAN%3ESort-Object%3C%2FSPAN%3E%26nbsp%3B-Property%26nbsp%3B%3CSPAN%3E'CPU'%3C%2FSPAN%3E%20%3CSPAN%3E-Descending%3C%2FSPAN%3E%3CSPAN%3E%20%7C%20%3C%2FSPAN%3E%3CSPAN%3ESelect-Object%3C%2FSPAN%3E%20%3CSPAN%3E-First%3C%2FSPAN%3E%20%3CSPAN%3E10%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%3CSPAN%3E%3C!--EndFragment%20--%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3C!--StartFragment%20--%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CDIV%3E%0A%3CDIV%20id%3D%22tinyMceEditorJoshua%20King_0%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3C%2FDIV%3E%0A%3CP%3E%3CSPAN%3E%3C!--EndFragment%20--%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3C!--EndFragment%20--%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1240454%22%20slang%3D%22en-US%22%3ERe%3A%20Fetch%20top%2010%20processes%20utilizing%20high%20CPU%20as%20shown%20in%20task%20manager%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1240454%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F62408%22%20target%3D%22_blank%22%3E%40Joshua%20King%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20the%20reply%20but%20I%20need%20the%20process%20name%20and%20id%20in%20percentage%20as%20shown%20in%20windows%20task%20manager.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
New Contributor

Hi

I have requirement where i have to fetch top 10 processes utilizing high cpu as shown in task manager.

 

Please guide me how to do it.

 

2 Replies
Highlighted

Hey @Prashantsahu, are you actually needing the "percentage" values like shown in the Task Manager (it is possible, just more work), or is it enough to still know the top 10 processes putting strain on the CPU?

 

Give this a go and see how you get on, start with Get-Process which returns all of the processes on the system.

 

Get-Process

 

Notice that there is a 'CPU(s)' property in the output, that's the "amount of processor time that the process has used on all processors, in seconds".

 

Next, you'll want to use Sort-Object to sort the list of processes using the most processor time. You'll note however that you can't sort by 'CPU(s)' as there's some trickery going on behind the scenes, but you can sort by 'CPU' and you'll also want to make this list descending so that the largest numbers are at the top.

 

Sort-Object -Property CPU -Descending

 

Finally, you only want the top 10, so use Select-Object and specify that you only want the first 10 objects.

 

Select-Object -First 10

 

Put that all together and you get something like this:

 

Get-Process | Sort-Object -Property 'CPU' -Descending | Select-Object -First 10

 

 

Highlighted

@Joshua King 

Thanks for the reply but I need the process name and id in percentage as shown in windows task manager.