Find Number of CPUs and Cores per CPU using Command Prompt
Asked Answered
H

5

49

I am trying to retrieve the Number of CPUs and Cores per CPU using Command Prompt. I have executed the following command:

wmic cpu get NumberOfCores, NumberOfLogicalProcessors/Format:List

I get this error: wmic' is not recognized as an internal or external command, operable program or batch file

I am executing this on a Windows Server 2008 R2 machine. I believe the 'wmic' command is compatible on this windows.

The directory I am running the command promt from is 'C:\Windows>

Any advice please?

Hoodoo answered 7/4, 2014 at 17:23 Comment(5)
Is C:\Windows\System32\Wbem on your path, and is there actually a file C:\Windows\System32\wbem\WMIC.exe?Marzipan
if you need the count of physical CPUs, use wmic computersystem get numberofprocessorsCaravan
@MichaelBurr I just have literally 'C:\Windows>wmic cpu get NumberOfCores, NumberOfLogicalProcessors/Format:List There is a filepath that leads to C:\Windows\System32\wbem\WMIC.exeHoodoo
@MichaelBurr I changed the directory to C:\Windows\System32\Wbem and now the command works. Thanks! Do you want to post as answer so I can accept?Hoodoo
To include even the CPU information you got to be running wmic cpu get SocketDesignation, NumberOfCores, NumberOfLogicalProcessors /Format:ListDyl
U
6

Based upon your comments - your path statement has been changed/is incorrect or the path variable is being incorrectly used for another purpose.

Unmade answered 9/4, 2014 at 1:40 Comment(0)
C
110

You can use the environment variable NUMBER_OF_PROCESSORS for the total number of processors:

echo %NUMBER_OF_PROCESSORS%
Chewning answered 4/9, 2015 at 10:5 Comment(8)
Does this environment variable exist on all versions of Windows??? That is incredibly useful. Are you aware of it's OS version compatibility?Calida
I only found that it was introduced in Windows 2000/NT. I guess it exists in every Windows desktop and server version after Windows 2000.Chewning
This delivers the total Number of Cores but not the number of CPUs.Soup
I confirmed that this shows the total number of cores across all socketsWrestle
This is not total number of cores in my hp Windows 10 Pro desktop pc. It is number of Logical processors. My pc has 6 cores and 12 processors so it gives 12. Is anyone knows how can I get that number 6 (number of cores)?Thury
This is not working windows or linux... I have received empty in windows and linux both. Why it is ?Lunular
This does not appear to be defined in my Powershell session. It just echoes the string %NUMBER_OF_PROCESSORS%.Prosenchyma
@ESilk, in PowerShell you must use $env:NUMBER_OF_PROCESSORS - see the conceptual about_Environment_Variables help topic.Pastrami
B
10

You can also enter msinfo32 into the command line.

It will bring up all your system information. Then, in the find box, just enter processor and it will show you your cores and logical processors for each CPU. I found this way to be easiest.

Belayneh answered 20/9, 2016 at 16:33 Comment(1)
Not really getting the information on the command line, though ;-)Eastward
U
6

Based upon your comments - your path statement has been changed/is incorrect or the path variable is being incorrectly used for another purpose.

Unmade answered 9/4, 2014 at 1:40 Comment(0)
C
5

If you want to find how many processors (or CPUs) a machine has the same way %NUMBER_OF_PROCESSORS% shows you the number of cores, save the following script in a batch file, for example, GetNumberOfCores.cmd:

@echo off
for /f "tokens=*" %%f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %%f

And then execute like this:

GetNumberOfCores.cmd

echo %NumberOfCores%

The script will set a environment variable named %NumberOfCores% and it will contain the number of processors.

Catalog answered 27/5, 2017 at 0:7 Comment(1)
When executing on the command line I had to replace the double %% with single %. Like: for /f "tokens=*" %f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %fWestbrooks
M
0

In order to check the absence of physical sockets run:

wmic cpu get SocketDesignation
Mammalogy answered 21/3, 2017 at 12:31 Comment(1)
this command returns CPU 1. What do you mean by absence of physical sockets? A CPU can't be present on a motherboard without a socket isn't it? I believe this command simply tells you the number of CPU sockets on your machine.Dyl

© 2022 - 2024 — McMap. All rights reserved.