Find Number of CPUs and Cores per CPU using Command Prompt

145,737

Solution 1

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

Solution 2

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

echo %NUMBER_OF_PROCESSORS%

Solution 3

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.

Solution 4

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.

Share:
145,737

Related videos on Youtube

Mustafa
Author by

Mustafa

Updated on July 09, 2022

Comments

  • Mustafa
    Mustafa almost 2 years

    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?

    • Michael Burr
      Michael Burr about 10 years
      Is C:\Windows\System32\Wbem on your path, and is there actually a file C:\Windows\System32\wbem\WMIC.exe?
    • Stephan
      Stephan about 10 years
      if you need the count of physical CPUs, use wmic computersystem get numberofprocessors
    • Mustafa
      Mustafa
      @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.exe
  • rubynorails
    rubynorails over 8 years
    Does this environment variable exist on all versions of Windows??? That is incredibly useful. Are you aware of it's OS version compatibility?
  • R1tschY
    R1tschY over 8 years
    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.
  • Magier
    Magier about 8 years
    This delivers the total Number of Cores but not the number of CPUs.
  • northben
    northben almost 8 years
    I confirmed that this shows the total number of cores across all sockets
  • RBT
    RBT about 7 years
    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.
  • BatteryBackupUnit
    BatteryBackupUnit over 6 years
    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 %f
  • Chucky
    Chucky almost 5 years
    Not really getting the information on the command line, though ;-)
  • Halil İbrahim Oymacı
    Halil İbrahim Oymacı about 4 years
    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)?
  • Chaminda Bandara
    Chaminda Bandara almost 4 years
    This is not working windows or linux... I have received empty in windows and linux both. Why it is ?

Related