Reputation: 500
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
Upvotes: 3
Views: 2710
Reputation:
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"
}
}
Upvotes: 0
Reputation: 500
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.
Upvotes: 1
Reputation: 2258
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);
}
Upvotes: 0
Reputation: 343141
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")
Upvotes: 2