57

How would I get total CPU Usage from Windows Command Prompt?:

Expected Output:

27%
Mike
  • 2,266
  • 10
  • 29
  • 37
  • 1
    related question: http://stackoverflow.com/questions/2415085/is-it-possible-to-know-the-cpu-utilization-from-command-line – Aziz Feb 01 '12 at 14:05
  • @Aziz - Related, but does not answer my question – Mike Feb 01 '12 at 14:06
  • 1
    @mdm typeperf "\processor(_total)\% processor time" - But it does not work on win 7 – Mike Feb 01 '12 at 14:06
  • 1
    @Mike: i know ... that's why I said "related", not "duplicate" :P – Aziz Feb 01 '12 at 14:07
  • I was after the CPU utilization value as shown in the task manager but none of the answers provided here worked for me. I used the command here instead: https://stackoverflow.com/a/54428361/2216471 – abaldwin99 Apr 14 '20 at 14:07

5 Answers5

105
C:\> wmic cpu get loadpercentage
LoadPercentage
0

Or

C:\> @for /f "skip=1" %p in ('wmic cpu get loadpercentage') do @echo %p%
4%
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
Alex K.
  • 171,639
  • 30
  • 264
  • 288
  • 3
    Kudos to you! I have a question for this. Do you have code for this getting the CPU Usage of a remote computer or a server? – Dhenn Nov 28 '13 at 11:52
  • 3
    In a doman environment with appropriate rights; `wmic /node:machinename cpu get loadpercentage` for other scenarios you will have to google *wmic remote machine* – Alex K. Nov 28 '13 at 12:26
  • 1
    @AlexK. adding /every:1 repeats this in a loop. – eel ghEEz Dec 12 '15 at 01:44
  • 3
    you can just use `wmic cpu get loadpercentage /value` to get the value directly instead of skipping a line – phuclv Jul 25 '18 at 01:23
  • Please note: if you get an error that wmic is not recognized, the WMIC.exe resides normally in the C:\windows\system32\wbem directory, so use C:\windows\system32\wbem\wmic.exe if need be – UnhandledExcepSean Jan 07 '19 at 14:58
  • 1
    `/value` didn't work for me, so with grep installed I used `@for /f %p in ('wmic cpu get loadpercentage ^| grep -P \d+') do @echo %p%` instead – airstrike Apr 26 '20 at 16:37
  • when I run: ```@for /f "skip=1" %p in ('wmic cpu get loadpercentage') do @echo %p%``` I get: "4% %". what can I do to just get "4"? – friendly joe Nov 26 '21 at 09:29
17

The following works correctly on Windows 7 Ultimate from an elevated command prompt:

C:\Windows\system32>typeperf "\Processor(_Total)\% Processor Time"

"(PDH-CSV 4.0)","\\vm\Processor(_Total)\% Processor Time"
"02/01/2012 14:10:59.361","0.648721"
"02/01/2012 14:11:00.362","2.986384"
"02/01/2012 14:11:01.364","0.000000"
"02/01/2012 14:11:02.366","0.000000"
"02/01/2012 14:11:03.367","1.038332"

The command completed successfully.

C:\Windows\system32>

Or for a snapshot:

C:\Windows\system32>wmic cpu get loadpercentage
LoadPercentage
8
mdm
  • 12,480
  • 5
  • 34
  • 53
8
typeperf "\processor(_total)\% processor time"

does work on Win7, you just need to extract the percent value yourself from the last quoted string.

PowerApp101
  • 1,798
  • 1
  • 18
  • 25
3

typeperf gives me issues when it randomly doesn't work on some computers (Error: No valid counters.) or if the account has insufficient rights. Otherwise, here is a way to extract just the value from its output. It still needs rounding though:

@for /f "delims=, tokens=2" %p in ('typeperf "\Processor(_Total)\% Processor Time" -sc 3 ^| find ":"') do @echo %~p%

Powershell has two cmdlets to get the percent utilization for all CPUs: Get-Counter (preferred) or Get-WmiObject:

Powershell "Get-Counter '\Processor(*)\% Processor Time' | Select -Expand Countersamples | Select InstanceName, CookedValue"

Or,

Powershell "Get-WmiObject Win32_PerfFormattedData_PerfOS_Processor | Select Name, PercentProcessorTime"


To get the overall CPU load with formatted output exactly like the question:

Powershell "[string][int](Get-Counter '\Processor(*)\% Processor Time').Countersamples[0].CookedValue + '%'"

Or,

 Powershell "gwmi Win32_PerfFormattedData_PerfOS_Processor | Select -First 1 | %{'{0}%' -f $_.PercentProcessorTime}"
Amit Naidu
  • 2,494
  • 2
  • 24
  • 32
0

For anyone that stumbles upon this page, none of the solutions here worked for me. I found this is the way to do it (in a batch file):

@for /f "skip=1" %%p in ('wmic cpu get loadpercentage /VALUE') do (
   for /F "tokens=2 delims==" %%J in ("%%p") do echo %%J
)
Denis
  • 11,796
  • 16
  • 88
  • 150