0

Is there any direct/simple command to get the RAM information through PS script, for example 4GB.

For eg. to retrieve OS Name I am using this command:

(Get-WmiObject Win32_OperatingSystem).Caption
Philippe
  • 3,945
  • 3
  • 38
  • 56
Unicorn
  • 295
  • 3
  • 10
  • 24
  • 2
    Possible duplicate of [How do I get total physical memory size using PowerShell without WMI?](https://stackoverflow.com/questions/17681234/how-do-i-get-total-physical-memory-size-using-powershell-without-wmi) – Paxz Oct 08 '18 at 10:41

2 Answers2

1

You are on the right path, using the WMI objects.

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?

You should consider switching to CIM.

(Get-CimInstance -ClassName Win32_ComputerSystem).totalphysicalmemory / (1024 * 1024 * 1024)

Read more about CIM vs. WMI here:

https://blogs.technet.microsoft.com/heyscriptingguy/2016/02/08/should-i-use-cim-or-wmi-with-windows-powershell/

Mötz
  • 1,682
  • 11
  • 17
0

Microsoft has said that CIM is the future.

((Get-CimInstance CIM_PhysicalMemory).Capacity | Measure-Object -Sum).Sum / (1024 * 1024 * 1024)
lit
  • 14,456
  • 10
  • 65
  • 119