如何在没有WMI的情况下使用PowerShell获得总物理内存大小? [英] How do I get total physical memory size using PowerShell without WMI?

查看:80
本文介绍了如何在没有WMI的情况下使用PowerShell获得总物理内存大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PowerShell来获取物理内存大小,但不使用get-wmiobject.

I'm trying to get the physical memory size using PowerShell, but without using get-wmiobject.

我一直在使用以下PS cmdlet来获取物理内存大小,但是该值会随着每次新的轮询而改变.

I have been using the following PS cmdlet to get the physical memory size, but the value changes with each new poll.

(get-counter -counter "\Memory\Available Bytes").CounterSamples[0].CookedValue + 
(get-counter -counter "\Memory\Committed Bytes").CounterSamples[0].CookedValue

通常,这给了我一个大概的值:8605425664字节

In general, this gives me a value around: 8605425664 bytes

我还在测试将这些计数器与从

I'm also testing the value I get from adding these counters with the returned value from

(get-wmiobject -class "win32_physicalmemory" -namespace "root\CIMV2").Capacity

这给我值:8589934592字节

This gives me the value: 8589934592 bytes

因此,不仅从计数器计算出的总物理内存发生了变化,而且它的值与WMI值相差了几兆字节.任何人都对不使用WMI如何获取物理内存大小有任何想法?

So, not only is the total physical memory calculated from counters changing, but it's value differs from the WMI value by a couple megabytes. Anyone have any ideas as to how to get the physical memory size without using WMI?

推荐答案

如果您不想使用WMI,建议您使用systeminfo.exe.但是,也许有更好的方法可以做到这一点.

If you don't want to use WMI, I can suggest systeminfo.exe. But, there may be a better way to do that.

(systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()

这篇关于如何在没有WMI的情况下使用PowerShell获得总物理内存大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆