Home » How to Get RAM Information in PowerShell

How to Get RAM Information in PowerShell

You can use the Get-CimInstance cmdlet in PowerShell to retrieve RAM details by querying the Win32_PhysicalMemory class.

The following method shows how you can do it with syntax.

Method 1: Get RAM details

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object -Property Capacity, MemoryType

This example will return information about RAM including the Capacity and MemoryType of each RAM module.

The following example shows how you can use this method.

How to Get RAM Details in PowerShell

The following PowerShell script will retrieve RAM details.

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object -Property Capacity, MemoryType

Output:

PowerShell get RAM details
PowerShell get RAM details

After running this script, it will display the Capacity and MemoryType of each RAM module

You can modify the above PowerShell script to get the total capacity of all RAM modules in gigabytes (GB), you can use the Measure-Object cmdlet.

(Get-CimInstance -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum / 1GB

Output:

PS C:\> (Get-CimInstance -ClassName Win32_PhysicalMemory | Measure-Object -Property Capacity -Sum).Sum / 1GB
32
(base) PS C:\>

This script calculates the sum of the Capacity property for all RAM modules and converts it from bytes to gigabytes (GB).

Conclusion

I hope the above article on getting RAM information in PowerShell is helpful to you.

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.