加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

powershell – Cim_PhysicalMemory和Win32_ComputerSystem返回不

发布时间:2020-12-14 02:18:17 所属栏目:Windows 来源:网络整理
导读:我正在尝试编写一个Power Shell脚本,显示服务器(512 GB的物理服务器)中安装的内存量. 我尝试了三种不同的方法,但得到了不同的结果. Win32_PhysicalMemory (Get-WmiObject Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum)/1GB 返回255.
我正在尝试编写一个Power Shell脚本,显示服务器(512 GB的物理服务器)中安装的内存量.
我尝试了三种不同的方法,但得到了不同的结果.

> Win32_PhysicalMemory

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

返回255.99 GB.
> Win32_ComputerSystem

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

这将返回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.

Taskmanager / systeminfo显示安装了512 GB.

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

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

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

解决方法

CIM_PhysicalMemory和Win32_PhysicalMemory是相同的[ 1].

This property is inherited from CIM_PhysicalMemory.

这是从[1]获得值的地方.

This value comes from the Memory Device structure in the SMBIOS version information. For SMBIOS versions 2.1 thru 2.6 the value comes from the Size member. For SMBIOS version 2.7+ the value comes from the Extended Size member.

SMBIOS标准说[2]

The Extended Size field is intended to represent memory devices larger than 32,767 MB (32 GB – 1 MB),which cannot be described using the Size field. This field is only meaningful if the value in the Size field is 7FFFh. For compatibility with older SMBIOS parsers,memory devices smaller than (32 GB – 1 MB) should be represented using their size in the Size field,leaving the Extended Size field set to 0.

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

请尝试验证您的SMBIOS版本

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

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

Win32_ComputerSystem查询来自Win32 api [3]的信息.

Total size of physical memory. Be aware that,under some circumstances,this property may not return an accurate value for the physical memory. For example,it is not accurate if the BIOS is using some of the physical memory. For an accurate value,use the Capacity property in Win32_PhysicalMemory instead.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读