views:

543

answers:

4

How can I find the number CPUs on 64 bit window 2003 servers? The answers in this thread did not work. Using Win32_ComputerSystem.NumberOfProcessors returns none.

I would prefer a way to do it using WMI if possible. I have a script that already his all the machines I need this info from grabbing disk info.

Thanks

+2  A: 

how about giving Win32_Processor a try

strComputer = "."
Set objWMIService = GetObject("winmgmts:"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
ghostdog74
Close. Here is the script I used:import wmiservers = ['xxx','yyy', 'TRIGOLDDB']for servername in servers: connection = wmi.connect_server (server=servername) #, user="tim", password="secret") c = wmi.WMI (wmi=connection) print servername for proc in c.Win32_Processor(): # print '{0:>10} {1} {2:3}GBs Free: {3:3}GBs ({4:5.2f}% free)'.format(disk.VolumeName,disk.Caption, (long(disk.Size)/1024/1024/1024), (long(disk.FreeSpace)/1024/1024/1024), (100.0 * long (disk.FreeSpace) / long (disk.Size))) print proc.name printIt lists 8 should be 2 (2 quad).
maybe you should post it not in comment section so that formatting is preserved, for the benefit of other readers.
ghostdog74
I took your suggestion - below. Formatting still a little off :-(
+1  A: 

Close. Here is the script I used:

import wmi

servers = ['XXX','YYY']

for servername in servers:
    connection = wmi.connect_server (server=servername)
    c = wmi.WMI (wmi=connection)
    print servername

    for proc in c.Win32_Processor():
        print proc.name
    print

The output is:

XXX

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

YYY

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

Intel(R) Pentium(R) III Xeon processor

I should just see two processecors for each server.

A: 

You can do this via a WMI query. The following script puts the SocketDesignation name for each logical CPU in a database table for the list of servers in the csv file. Once the table is populated running the following query will give you a count of physical and logical processors:

select servername, COUNT(cpuname) 'LogicalCPUCount', COUNT(distinct cpuname) 'PhysicalCPUCount'
from tmp_cpu
group by servername

* WMI script - you will need to adjust connections and create the tmp_cpu table prior to running *

$query = "delete sqlserverinventory.dbo.tmp_cpu"

Invoke-Sqlcmd -Query $query -ServerInstance "xxxxxxxx"

 Invoke-Sqlcmd -Query "select servername from sqlserverinventory.dbo.server where servername in (select servername from sqlserverinventory.dbo.vw_Instance_Autoload);" -ServerInstance "xxxxxxxx" | out-file -filepath "v:\scripts\server_list.csv"

 (Get-Content v:\scripts\server_list.csv) | where {$_.readcount -gt 3} | Set-Content v:\scripts\server_list.csv

$servers = Get-Content "V:\scripts\server_list.csv"
## $servers = Invoke-Sqlcmd -Query "select servername from sqlserverinventory.dbo.vw_Instance_Autoload;" -ServerInstance "xxxxxxxx"

foreach ($server in $servers){

    $server = $server.Trim()

    $SQLServices = Get-WmiObject -ComputerName $server -Namespace "root\CIMV2" -query "SELECT SocketDesignation FROM Win32_Processor where CPUStatus=1 or CPUStatus=4" 

    forEach ($SQLService in $SQLServices) {

        $PhysicalCPU = $SQLService.SocketDesignation

        $insert_query = "INSERT INTO sqlserverinventory.dbo.tmp_cpu (ServerName,CPUName) VALUES('$server','$PhysicalCPU')"

        ## "sql - $insert_query" 
        Invoke-Sqlcmd -Query $insert_query -ServerInstance "xxxxxxxx"
     } 
 }
Mike Ryder
A: 

this will work:

        ManagementObjectSearcher mgmtObjects = new ManagementObjectSearcher("Select * from Win32_ComputerSystem");

        foreach (var item in mgmtObjects.Get())
        {
            Console.WriteLine("NumberOfProcessors:" + item.Properties["NumberOfProcessors"].Value);
            Console.WriteLine("NumberOfLogicalProcessors:" + item.Properties["NumberOfLogicalProcessors"].Value);
        }
Tom Frey