Detailed Information about RAM in PowerShell

Memory or RAM is something that is vital to the computer. Without it, it simply wont run. To explain it short; Memory is the computers temporary workspace. It’s a place that the central Processor Unit (also called CPU) stores random data that need to be accessed quickly as it operates in a very high speed compared to any hard drive. Drives such as m.2 and solid state disk (also called SSD) is closing in on the speed that computer memory possess, but is not optimal yet.

But we are not going to discuss hard drives in this article, or how RAM works in theory. We are here to see how we can extract out information about the memory sticks inside our computer using PowerShell.

For those of you who are unfamiliar with PowerShell, i can tell you this;
It’s a command-line shell and scripting language. If you have been using the “command prompt” terminal (CMD), it’s just like this but only more advanced. What that means is that there is a whole lot more you can do in this tool compared to the command prompt tool.
Honestly, we could have dedicated a huge article to describe what PowerShell is that would take an hour or more to read through, but we are not going to do that. If you are interested in learning more about PowerShell we suggest you check out this page over at Microsoft which will answer most of your questions.

Drop out everything on RAM

Okay, so we want to extract the information.
First we need to start PowerShell.
Click on “Start” then type “powershell” and press “Enter”.
This should bring up a blue command line view.

For this operation we will read the CIM (Computer Integrated Manufacturing) data of a specific class, more specifically the data that the manufacturer have set on the hardware.

Let’s first of all just drop out everything we have on the memory sticks.
To do that we need to enter the following command:

Get-CimInstance -ClassName Win32_PhysicalMemory

This will produce a full page of information about your memory sticks. Much of it would be irrelevant to us, and many tags are missing a value so they show up empty which is perfectly normal.

But this is too much, and too messy!

Yes, we agree! This show us too much information that we don’t need and makes everything hard to read.

Let’s try to add some filters on the command to only get the information that most of us care about. To do this we have selected a few tags that are most useful for the common user. These would be;

  • Manufacturer
  • Part Number
  • Capacity
  • Clock speed
  • DIMM slot it’s installed in

To filter the output to only show these tags we use the following command;

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object -Property Manufacturer, PartNumber, Capacity, ConfiguredClockSpeed, DeviceLocator 

This will produce a much narrow output that can at least only show us what most of us are looking for.

But it’s still a bit dirty

We totally agree!
The tags could be hard to understand, and the capacity; what kind of number is that!
Lets fix the looks of it a bit by changing some of the names, and add math to the capacity section to calculate it into a better looking number.

To do that simply add the following command that is the same as before. But this time we have added math and text wrapping to the command:

Get-CimInstance -ClassName Win32_PhysicalMemory | 
Select-Object -Property Manufacturer, @{Name="Model";Expression={$_.PartNumber}}, @{Name="Size";Expression={[math]::round(($_.Capacity/1gb))}}, @{Name="Clock Speed";Expression={$_.ConfiguredClockSpeed}}, @{Name="RAM Slot";Expression={$_.DeviceLocator}} 

This looks more like it.
The names have been corrected, and the capacity has become more readable.

But what if i want to show what the capacity number means?

So glad you ask!
Even though we know based on the command we just typed in what that number means, its still nice to show it off with an ending.
Let’s add the gigabyte sign behind it. To do that we need to modify that last command just a little so it looks like this:

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object -Property Manufacturer, @{Name="Model";Expression={$_.PartNumber}}, @{Name="Size";Expression={[math]::round(($_.Capacity/1gb)).ToString()+" GB"}}, @{Name="Clock Speed";Expression={$_.ConfiguredClockSpeed}}, @{Name="RAM Slot";Expression={$_.DeviceLocator}} 

This convert the number from an integer to a string, so that we can easily add more text (which is in string format) to that line.

Can i get it in a table looking format?

Yes! you sure can..
To display it in a table format that can be exported to an excel file we change the word “Select-Object” to “Format-Table”.
The command would then look like this:

Get-CimInstance -ClassName Win32_PhysicalMemory | Format-Table -Property Manufacturer, @{Name="Model";Expression={$_.PartNumber}}, @{Name="Size";Expression={[math]::round(($_.Capacity/1gb)).ToString()+" GB"}}, @{Name="Clock Speed";Expression={$_.ConfiguredClockSpeed}}, @{Name="RAM Slot";Expression={$_.DeviceLocator}} 

I want to export it to Excel

Okay we will admit it would be nice to have this in a pretty Excel sheet.
To do this, we need to change it back from “Format-Table” to “Select-Object”.
The reason for this is that the Format-Table command is only to show it like this in the terminal window. Exporting it with this command would simply display random numbers.

So to export it we use the following command where we add the export function at the end:

Get-CimInstance -ClassName Win32_PhysicalMemory | Select-Object -Property Manufacturer, @{Name="Model";Expression={$_.PartNumber}}, @{Name="Size";Expression={[math]::round(($_.Capacity/1gb)).ToString()+" GB"}}, @{Name="Clock Speed";Expression={$_.ConfiguredClockSpeed}}, @{Name="RAM Slot";Expression={$_.DeviceLocator}} | Export-Csv -Path .\RAMinfo.csv -notypeinformation

This will save the information to a CSV file that can be used with Excel.
When you open the file, it will sadly show everything in one column.
Having the PowerShell script to separate them would require us to build an unnecessary huge script.

To solve this easily, we use the “Text to Columns” feature that exists in Excel. Here we can choose to separate the text based on commas which the PowerShell script have added for us.

Applying this the result would be something like in the picture below.

We hope this was of any help.
Thanks for reading, and stay curious..