A similar solution as the others, but using Get-CounterGet-Counter
instead of Get-Process.
While(1) { $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft Get-a}Process
:
While(1) { $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}`
Path InstanceName CookedValue
---- ------------ -----------
\\server_name\process(_total)\% processor time _total 4806.03969127454
\\server_name\process(idle)\% processor time idle 1103.7573538257
\\server_name\process(program#2)\% processor time program 749.692930701698
\\server_name\process(program#5)\% processor time program 563.424255927765
\\server_name\process(program#1)\% processor time program 535.714866291973
\\server_name\process(program#6)\% processor time program 455.665518455242
\\server_name\process(program#3)\% processor time program 426.416718284128
\\server_name\process(program)\% processor time program 395.628507577693
\\server_name\process(program#4)\% processor time program 335.591496700144
\\server_name\process(microsoftedgecp#2)\% processor time microsoftedgecp 129.310484967028
\\server_name\process(system)\% processor time system 80.0493478367316
\\server_name\process(chrome#8)\% processor time chrome 1.53941053532176
Path InstanceName CookedValue
---- ------------ -----------
\\server_name\process(_total)\% processor time _total 4806.03969127454
\\server_name\process(idle)\% processor time idle 1103.7573538257
\\server_name\process(program2)\% processor time program 749.692930701698
\\server_name\process(program5)\% processor time program 563.424255927765
\\server_name\process(program1)\% processor time program 535.714866291973
\\server_name\process(program6)\% processor time program 455.665518455242
\\server_name\process(program3)\% processor time program 426.416718284128
\\server_name\process(program)\% processor time program 395.628507577693
\\server_name\process(program4)\% processor time program 335.591496700144
\\server_name\process(microsoftedgecp2)\% processor time microsoftedgecp 129.310484967028
\\server_name\process(system)\% processor time system 80.0493478367316
\\server_name\process(chrome8)\% processor time chrome 1.53941053532176
I found most of the other solutions here using get-processGet-Process
report the total CPU time since the start of the process. That, which wasn't useful on my server that stays up 24/7 where the top result was always just svchost
and system
at millions of seconds. A true top
or Task Manager equivalent would give a snapshot of the CPU usage recorded recently over some fixed time and Get-Counter provides that. Since this Superuser post is still the top Google result for "powershell top", I figured this alternative is worth contributing.
- A true
top
or Task Manager equivalent would give a snapshot of the CPU usage recorded recently over some fixed time and Get-Counter
provides that. I figured this alternative is worth contributing since this question is still the top Google result for powershell top
.
My command is basedBased on exampleExample 13 from the Get-Counter docs: Get-Counter
https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Diagnostics/Get-Counter.
Here's, a breakdown of the one-liner so you can more easily modify it to your needscommand:
While(1) {
just loops itWhile(1) {
: Creates a loop
get-counter '\Process(*)\% Processor Time'
selects the CPU % data. This command seems to take a significant amount of time to return, so no need to sleep
get-counter '\Process(*)\% Processor Time'
: Selects CPU % data, which takes a significant amount of time to return, so no need to sleep
cls
clear for the new tablecls
: Clear for the new table
sort -des CookedValue
CookedValue is the field we're intetested in, sort to put the biggest on topsort -des CookedValue
: Sort largest on top for CookedValue
[field we're interested in]
select -f 15
display first 15select -f 15
: Display first 15
ft -a
display in formatted tableft -a
: Display in formatted table