如何获取64位机器上的处理器数量?

发布于 2024-07-26 20:48:40 字数 290 浏览 8 评论 0原文

如何找到 64 位 Windows 2003 服务器上的 CPU 数量? 此线程中的答案不起作用。 使用 Win32_ComputerSystem.NumberOfProcessors 不会返回任何内容。

如果可能的话,我更喜欢使用 WMI 来完成此操作。 我有一个脚本,它已经是我需要通过抓取磁盘信息获取此信息的所有机器。

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

弱骨蛰伏 2024-08-02 20:48:40

尝试一下 Win32_Processor 怎么样?

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

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")
满地尘埃落定 2024-08-02 20:48:40

关闭。 这是我使用的脚本:

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

输出是:

XXX

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

YYY

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

英特尔(R) 奔腾(R) III 至强处理器

我应该只看到每个服务器有两个处理器。

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.

请爱~陌生人 2024-08-02 20:48:40

这会起作用:

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

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);
        }
一片旧的回忆 2024-08-02 20:48:40

您可以通过 WMI 查询来执行此操作。 以下脚本将每个逻辑 CPU 的 SocketDesignation 名称放入 csv 文件中服务器列表的数据库表中。 填充表后,运行以下查询将为您提供物理和逻辑处理器的计数:

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

***** WMI 脚本 - 您需要在运行 ***** 之前调整连接并创建 tmp_cpu 表

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

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"
     } 
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文