本文介绍了Cim_PhysicalMemory 和 Win32_ComputerSystem 返回不同的内存量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个 PowerShell 脚本,以显示服务器(具有 512 GB 的物理服务器)中安装的内存量.
我尝试了三种不同的方法,但得到了不同的结果.

I'm trying to write a PowerShell script that shows the amount of memory installed in a server (a physical server with 512 GB).
I've tried three different methods and I get different results.

  1. Win32_PhysicalMemory

(Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum)/1GB

这将返回 255.99 GB.

This returns 255.99 GB.

Win32_ComputerSystem

$InstalledRAM = Get-WmiObject -Class Win32_ComputerSystem
[Math]::Round(($InstalledRAM.TotalPhysicalMemory/1GB), 2)

这将返回 511.88 GB.

This returns 511.88 GB.

Cim_PhysicalMemory

$MaxRam = 0
$RamPool = (Get-CimInstance -Class "Cim_PhysicalMemory" | % {$_.Capacity})

foreach ($RamBank in $RamPool) {
    $MaxRam += $RamBank/1024/1024
}

这将返回 255.99 GB.

This returns 255.99 GB.

Taskmanager/systeminfo 显示安装了 512 GB.

Taskmanager/systeminfo show there is 512 GB installed.

当我使用 Win32_PhysicalMemory 打印出安装在不同内存条中的内存,我得到 8 个 32 GB 的内存条.但我确定服务器包含 512 GB.

When I use Win32_PhysicalMemory to print out the memory installed in the different memory banks, I get 8 banks of 32 GB.But I'm sure the server contains 512 GB.

有人可以向我解释为什么方法 1 和方法 3 只返回 256 GB 吗?

Can someone explain to me why method 1 and 3 only return 256 GB?

更新:
当我查看 bios 时,我看到为每个物理处理器分配了 256 GB.我的知识不是那么先进,但是否有可能我必须首先请求 NUMA 节点,然后 foreach 节点检索分配给它的内存量?或者 Powershell 无法做到这一点?

Update:
When I look in the bios I see that there is 256 GB assigned to each physical processor. My knowledge is not so advanced but is it possible that I have to request the NUMA-nodes first and foreach node retrieve the amount of memory assigned to it? Or is this not possible with Powershell?

推荐答案

CIM_PhysicalMemoryWin32_PhysicalMemory 是相同的 [1].

CIM_PhysicalMemory and Win32_PhysicalMemory are the same [1].

此属性继承自 CIM_PhysicalMemory.

这是从[1].

该值来自 SMBIOS 版本信息中的 Memory Device 结构.对于 SMBIOS 2.1 到 2.6 版本,该值来自 Size 成员.对于 SMBIOS 2.7+ 版,该值来自扩展大小成员.

SMBIOS 标准说 [2]

The SMBIOS standard says [2]

扩展大小字段旨在表示大于 32,767 MB (32 GB - 1 MB) 的内存设备,无法使用大小字段进行描述.此字段仅在 Size 字段中的值为 7FFFh 时才有意义.为了与旧的 SMBIOS 解析器兼容,小于 (32 GB - 1 MB) 的内存设备应该使用它们在 Size 字段中的大小来表示,而将 Extended Size 字段设置为 0.

如您所说,您有 8x64GB,但显示为 8x32GB,这对我来说不像 NUMA 问题.如果是 NUMA,我希望你能显示 4x32GB.另外,我有一个带有 8x32GB 和 2 个套接字的服务器.因此,如果是 NUMA 问题,我希望在我的盒子上看到同样的问题.但是,我正确显示了金额.看起来您的 BIOS 使用 2.7.1 之前的 SMBIOS 标准结构,但这很奇怪,因为它是 2011 年的.

As you say, you have 8x64GB, but displayed 8x32GB, it doesn't like like a NUMA issue to me. If it's NUMA, I'd expect you get 4x32GB displayed. Also, I have a server with 8x32GB and 2 sockets. Hence, if it's a NUMA issue, I'd expect to see the same issue on my box. However, I get the amount displayed correctly. It looks like your BIOS uses SMBIOS standad strcuture before 2.7.1, which is strange though, as it's from 2011.

请尝试使用

(Get-CimInstance -ClassName Win32_BIOS) | Select-Object SMBIOS*

对我来说,SMBIOSVersion 返回供应商的 BIOS 版本号而不是标准,但 SMBIOSMajorVersionSMBIOSMinorVersion 返回正确的值.

For me, SMBIOSVersion returns the vendor's BIOS version number instead of the standard, but SMBIOSMajorVersionand SMBIOSMinorVersion are returning the proper value.

Win32_ComputerSystem 从 Win32 api 查询信息 [3].

Win32_ComputerSystem queries the information from the Win32 api [3].

物理内存的总大小.请注意,在某些情况下,此属性可能不会返回物理内存的准确值.例如,如果 BIOS 正在使用某些物理内存,则它是不准确的.要获得准确的值,请改用 Win32_PhysicalMemory 中的容量属性.

这篇关于Cim_PhysicalMemory 和 Win32_ComputerSystem 返回不同的内存量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 21:14