0

I have been unable to discover a way to determine what processors/CPUs/sockets are present in a PC/Server.

Any suggestions?

5 Answers 5

1

The WMI WIN32_Processor class gives basic info about installed processors..

1

Try:

' *** Get the server name

  set wsh_shell = wscript.CreateObject("Wscript.Shell")
  set wsh_env = wsh_shell.Environment("PROCESS")
  server_name =  wsh_env("COMPUTERNAME")
  set wsh_env = nothing
  set wsh_shell = nothing

' *** Open the WMI service

  set wmi_service = GetObject("winmgmts:\\" & server_name)

' *** Processor

  set wmi_objectset = wmi_service.InstancesOf("Win32_Processor")

  for each wmi_object in wmi_objectset
    wscript.echo cstr(wmi_object.MaxClockSpeed) & " - " _
               & cstr(wmi_object.NumberOfCores)
  next

  set wmi_service = nothing

I've had the script print the clock speed, but you can look at any of the properties mention in the link in Stuart Dunkeld's post.

John Rennie

1

In addition to the Win32_Processor class mentioned in other answers, you also have the Win32_ComputerSystem class which has the NumberOfLogicalProcessors and NumberOfProcessors values. The notes in the documentation about OS support for those two values are slightly incorrect. XP does support the NumberOfLogicalProcessors value since SP3. I'm guessing Win2003 will also support it whenever its next service pack is released as well.

1
  • can I ask what results are returned if you call these classes on VMWare. Does it still return you the physical processor info, or the VMWare ones? If it is the virtual ones, do you know of a way to get the physical ones on the machine?
    – Ryk
    Aug 16, 2011 at 6:30
1

On old version of Windows (Win2003, XP SP2 or earlier) Win32_Processor.SocketDesignation always returns 'Proc 1' for a logical processor. This script will work on any version of Windows.

$procs = [object[]]$(get-WMIObject Win32_Processor) # force into array even if only 1
if ($procs[0].NumberOfCores -eq $null) { # old version
  $physCount = new-object hashtable
  $procs |%{$physCount[$_.SocketDesignation] = 1}
  "Physical processors: {0}; Logical processors: {1}" -f $physCount.count, $procs.count
} else { # new version
  "Physical processors: {0}; Logical processors: {1}" -f $procs.count, `
    $($procs|measure-object NumberOfLogicalProcessors -sum).Sum
}
1

Please be aware that on Windows Server 2003, SP1 or SP2 the NumberOfCores property of Win32_Processor is not available unless you installed a hotfix 180973 (for x86 or x64) as outlined in this KB: http://support.microsoft.com/kb/932370 . The same for Windows XP SP2 - see KB: http://support.microsoft.com/kb/936235 There is a link on how to request the hotfix by email at the top of each KB page. This property first appeared on Windows Vista.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .