Check A Computer’s Memory with PowerShell’s CIM_PhysicalMemory
Our mission to use PowerShell to interrogate a computer’s physical memory, to see the properties of that RAM stick(s). Goals include discovering the capacity, speed and data width. We also have pure PowerShell goals, to research with Get-member and to control the display with format-table -auto.
Topics for PowerShell Memory
- Preparation with Get-Help
- Research Properties with Get-Member
- Simple Example to Display CIM_PhysicalMemory
- Refined Example Using More Properties
When you discover a new PowerShell command, it benefits from being surveyed with what I call the ‘Trusty Twosome’. Research with Get-Help and Get-Member and reveal new scripting possibilities for Get-WmiObject CIM_PhysicalMemory. To see what I mean start with Get-Help.
The master cmdlet is Get-WmiObject, and as we will see later, PowerShell’s CIM_PhysicalMemory is a class of this object.
# Help with PowerShell WMI object:
Note 1: If you prefer examples: help gci -full
Get-Help unearths useful parameters such as -class and -computerName (-computer also works).
A simple script to display your computer’s physical memory.
# A simple command to display CIM_PhysicalMemory
Those with a VBScript, or SQL background may be more familiar with query and select statement. This achieves the same result, but is only useful if you wished to modify "Select *".
# Display CIM_PhysicalMemory using -query and "Select"
Get-WmiObject -query "Select * from CIM_PhysicalMemory"
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft’s operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try – it’s free.
# Properties for PowerShell memory object:
Get-WmiObject CIM_PhysicalMemory |Get-Member
Note 2: If you enjoy aliases: gwmi CIM_PhysicalMemory | gm
Note 3: If you are fond of filters: gwmi CIM_PhysicalMemory| gm -Membertype property
Get-Member (gm) reveals a whole host of properties that you don’t normally see in the Device Manager.
Refined Example: Using Properties We Researched with Get-Member
Get-WmiObject -query "Select * from CIM_PhysicalMemory" |`
Format-Table name, Capacity, DataWidth, Speed -auto
Summary: PowerShell Memory CIM_PhysicalMemory
We want to find the computer’s physical memory using PowerShell. In particular, we want the capacity, speed and data width. Note in passing how we investigated with Get-member and to control the display with format-table -auto.
If you like this page then please share it with your friends
See More Microsoft PowerShell WMI Examples:
Please email me if you have a script examples. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.