Determine CPU processors vs. sockets though WMI

11,059

Solution 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

Solution 2

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

Solution 3

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
}

Solution 4

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.

Solution 5

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.

Share:
11,059

Related videos on Youtube

sweetsecret
Author by

sweetsecret

Microsoft SQL Server Administrator

Updated on September 17, 2022

Comments

  • sweetsecret
    sweetsecret over 1 year

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

    Any suggestions?