Advanced Windows PowerShell Scripting Video Training

Advanced Windows PowerShell Scripting Video Training
Advanced Windows PowerShell Scripting Video Training

Wednesday, June 8, 2011

How to determine the number of physical processors on a client in PowerShell.

There seems to be a bit of a debate on the internet about this one.  I executed the following PowerShell command on 2 different computers:

Get-WMIObject Win32_ComputerSystem | FL *

 

I executed it on a laptop with 1 physical processor with 4 logical processors and received the following results:

 

image

 

I then executed it again on a desktop with 1 physical processor and 8 logical processors:

 

image

 

From my testing, the NumberOfProcessors property seems to provide the correct number of physical processors.

 

I got curios and ran that PowerShell code on a virtual machine with 1 assigned processor:

 

image

 

I also ran it on a virtual machine with 4 processors assigned to it:

 

image

 

OK, so how do you know if you are looking at a virtual machine or a physical machine?  A couple of properties higher in the list you will see Model.  If this was a virtual machine, it would say Virtual Machine.

 

image

1 comment:

Brandon Ryan said...

To get the number of physical CPU sockets, you must count how many objects are returned by "get-wmiobject win32_processor"

---

$myArray = @()
$myArray += get-wmiobject win32_processor
$myArray.Count