[英]Windows 7 - Get RAM details using powershell script
Is there any direct/simple command to get the RAM information through PS script, for example 4GB. 是否有任何直接/简单的命令可以通过PS脚本获取RAM信息,例如4GB。
For eg. 例如。 to retrieve OS Name I am using this command:
检索操作系统名称我正在使用此命令:
(Get-WmiObject Win32_OperatingSystem).Caption
You are on the right path, using the WMI objects. 您在使用WMI对象的正确路径上。
The quick answer is: 快速的答案是:
(Get-WmiObject Win32_ComputerSystem).totalphysicalmemory / (1024 * 1024 * 1024)
It is based on this answer: 它基于以下答案:
How to get total physical memory (ram) information in GB by WMI query? 如何通过WMI查询获取GB中的总物理内存(RAM)信息?
You should consider switching to CIM. 您应该考虑切换到CIM。
(Get-CimInstance -ClassName Win32_ComputerSystem).totalphysicalmemory / (1024 * 1024 * 1024)
Read more about CIM vs. WMI here: 在此处阅读有关CIM与WMI的更多信息:
https://blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell/ https://blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell/
微软曾表示CIM是未来。
((Get-CimInstance CIM_PhysicalMemory).Capacity | Measure-Object -Sum).Sum / (1024 * 1024 * 1024)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.