Get Total Number of Cores from a computer WITHOUT HyperThreading

David Lago picture David Lago · Sep 1, 2016 · Viewed 32.3k times · Source

This is a tough one.

I need to use a command to output the exact number of cores from my servers.

My tests:

  • X: On a Windows server with 4 processors (sockets) and 2 cores each without HT.
  • Y: On a Windows Server with 2 processors (sockets) and 6 cores each with HT.

GetSystemInfo only gets me the number of processors installed: 4 for X, 2 for Y.

|                | X: 8 cores  | Y: 12 cores |
|                | 4x2 (no HT) | 2x6 (HT)    |
|----------------|-------------|-------------|
| Desired output | 8           | 12          |
| GetSystemInfo  | 4           | 2           | 

%NUMBER_OF_PROCESSORS% is a good one, but it takes HT into account. It tells me 8 for X and 24 for Y (since it has HT, I needed it to show 12 instead).

|                        | X: 8 cores  | Y: 12 cores |
|                        | 4x2 (no HT) | 2x6 (HT)    |
|------------------------|-------------|-------------|
| Desired output         | 8           | 12          |
| GetSystemInfo          | 4           | 2           | 
| %NUMBER_OF_PROCESSORS% | 8           | 24          |

"wmic cpu get NumberOfCores" gets me info for each socket. For example:

X:

>wmic cpu get NumberOfCores
NumberOfCores
2
2
2
2

Y:

>wmic cpu get NumberOfCores
NumberOfCores
6
6

Meaning

|                            | X: 8 cores  | Y: 12 cores |
|                            | 4x2 (no HT) | 2x6 (HT)    |
|----------------------------|-------------|-------------|
| Desired output             | 8           | 12          |
| GetSystemInfo              | 4           | 2           | 
| %NUMBER_OF_PROCESSORS%     | 8           | 24          |
| wmic cpu get NumberOfCores | 2,2,2,2     | 6,6         |

Sigh.

I wished to keep it simple, inside the CMD, but I'm thinking about starting a Powershell script to do all that math and stuff.

Any thoughts?

Answer

Syc picture Syc · Dec 20, 2018

suggested command does not work on computer with mote than 64 logical cores

(Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors

provide number of logical cores (HT cores)