Unicorn
Unicorn

Reputation: 295

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.

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

(Get-WmiObject Win32_OperatingSystem).Caption

Upvotes: 0

Views: 4939

Answers (2)

lit
lit

Reputation: 16256

Microsoft has said that CIM is the future.

((Get-CimInstance CIM_PhysicalMemory).Capacity | Measure-Object -Sum).Sum / (1024 * 1024 * 1024)

Upvotes: 1

Mötz
Mötz

Reputation: 1732

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/

Upvotes: 1

Related Questions