Reputation: 295
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
Reputation: 16256
Microsoft has said that CIM is the future.
((Get-CimInstance CIM_PhysicalMemory).Capacity | Measure-Object -Sum).Sum / (1024 * 1024 * 1024)
Upvotes: 1
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:
Upvotes: 1