How to get the number of processors on a 64-bit machine?

How can I find the number of processors on servers with a 64-bit window in 2003? The answers in this thread did not work. Using Win32_ComputerSystem.NumberOfProcessors does not return.

I would prefer to do this using WMI, if possible. I have a script that already to all its machines I need this information from capturing disk information.

thanks

+3
source share
4 answers

how to give win32_Processor a try

strComputer = "."
Set objWMIService = GetObject("winmgmts:"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")    
Set colItems = objWMIService.ExecQuery("Select * from Win32_Processor")
+2
source

To 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

Output:

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 handlers for each server.

+1

You can do this with a WMI request. The following script puts the SocketDesignation name for each logical processor in the database table for the list of servers in the csv file. After filling out the table, the following query will give you the number 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 configure connections and create a tmp_cpu table before starting *****

$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"
     } 
 }
0
source

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);
        }
0
source

Source: https://habr.com/ru/post/1712678/


All Articles