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,817
  • 3
  • 37
  • 55
Unicorn
  • 225
  • 2
  • 8
  • 22
  • 1
    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,552
  • 10
  • 15
0

Microsoft has said that CIM is the future.

((Get-CimInstance CIM_PhysicalMemory).Capacity | Measure-Object -Sum).Sum / (1024 * 1024 * 1024)
lit
  • 13,209
  • 9
  • 55
  • 92