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
1

2 Answers 2

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/

Sign up to request clarification or add additional context in comments.

Comments

1

Microsoft has said that CIM is the future.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.