Skip to main content
Remove stray backtick
Source Link
Bob
  • 62k
  • 25
  • 199
  • 222
While(1) {  $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}`
While(1) {  $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}`
While(1) {  $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}
Added correct markdown for monospaced code ; Applied syntax highlighting ; Grammatical corrections
Source Link
JW0914
  • 8.3k
  • 7
  • 31
  • 50

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 it

    While(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 table

    cls: Clear for the new table

  • sort -des CookedValue CookedValue is the field we're intetested in, sort to put the biggest on top

    sort -des CookedValue: Sort largest on top for CookedValue [field we're interested in]

  • select -f 15 display first 15

    select -f 15: Display first 15

  • ft -a display in formatted table

    ft -a: Display in formatted table

A similar solution as the others, but using Get-Counter instead of Get-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

I found most of the other solutions here using get-process report the total CPU time since the start of the process. That 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.

My command is based on example 13 from the Get-Counter docs: 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 needs:

  • While(1) { just loops it
  • 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
  • cls clear for the new table
  • sort -des CookedValue CookedValue is the field we're intetested in, sort to put the biggest on top
  • select -f 15 display first 15
  • ft -a display in formatted table

A similar solution as others, but using Get-Counter instead of Get-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(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-Process report the total CPU time since the start of the process, which wasn't useful on my server that stays up 24/7 where the top result was always 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. I figured this alternative is worth contributing since this question is still the top Google result for powershell top.

Based on Example 13 from the Get-Counter docs, a breakdown of the command:

  • While(1) {: Creates a loop

  • 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 table

  • sort -des CookedValue: Sort largest on top for CookedValue [field we're interested in]

  • select -f 15: Display first 15

  • ft -a: Display in formatted table

Source Link

A similar solution as the others, but using Get-Counter instead of Get-Process.

While(1) { $p = get-counter '\Process(*)\% Processor Time'; cls; $p.CounterSamples | sort -des CookedValue | select -f 15 | ft -a}

Sample output:

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

I found most of the other solutions here using get-process report the total CPU time since the start of the process. That 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.

My command is based on example 13 from the Get-Counter docs: 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 needs:

  • While(1) { just loops it
  • 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
  • cls clear for the new table
  • sort -des CookedValue CookedValue is the field we're intetested in, sort to put the biggest on top
  • select -f 15 display first 15
  • ft -a display in formatted table