Skip to main content

How to Get RAM Information in PowerShell

• 3 min read
powershell ram memory get-ciminstance

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

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

Get Total RAM in Gigabytes

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

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

Get Detailed RAM Information

To get more detailed information about your RAM:

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object Manufacturer, PartNumber, SerialNumber, @{N='Capacity(GB)';E={$_.Capacity/1GB}}, Speed

This provides manufacturer, part number, serial number, capacity, and speed of each RAM module.

Conclusion

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


WMI & CIM Operations

  • PowerShell Get-WmiObject - Query WMI information
  • PowerShell Get-CimInstance - Query system information via CIM
  • PowerShell Win32 Classes - WMI class reference

System Monitoring

Data Selection & Filtering

Data Aggregation & Calculation

  • PowerShell Measure-Object - Calculate memory totals
  • PowerShell Group-Object - Group by memory type

Display & Formatting

Control Flow & Logic

Variables & Collections

Output & Export

String & Number Operations

Functions & Automation

  • PowerShell Functions - Create memory monitoring functions
  • PowerShell Measure-Object - Calculate memory statistics

Advanced Monitoring

Comprehensive Guides