Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get total physical memory size using PowerShell without WMI?

I'm trying to get the physical memory size using PowerShell, but without using get-wmiobject.

I have been using the following PS cmdlet to get the physical memory size, but the value changes with each new poll.

(get-counter -counter "\Memory\Available Bytes").CounterSamples[0].CookedValue + 
(get-counter -counter "\Memory\Committed Bytes").CounterSamples[0].CookedValue

In general, this gives me a value around: 8605425664 bytes

I'm also testing the value I get from adding these counters with the returned value from

(get-wmiobject -class "win32_physicalmemory" -namespace "root\CIMV2").Capacity

This gives me the value: 8589934592 bytes

So, not only is the total physical memory calculated from counters changing, but it's value differs from the WMI value by a couple megabytes. Anyone have any ideas as to how to get the physical memory size without using WMI?

like image 514
eltaco431 Avatar asked Jul 16 '13 15:07

eltaco431


People also ask

How do I get disk information in PowerShell?

Run the command get-wmiobject -class win32_logicaldisk to look up core information about each connected hard drive. The command returns drive letters and types, the overall size and free space in bytes, and the volume name.

How do I get CPU information in PowerShell?

In the Run window, type: dxdiag (without quotation marks). In the DirectX Diagnostic Tool window, in the System tab, general information about the computer processor will be displayed.


2 Answers

If you don't want to use WMI, I can suggest systeminfo.exe. But, there may be a better way to do that.

(systeminfo | Select-String 'Total Physical Memory:').ToString().Split(':')[1].Trim()
like image 183
ravikanth Avatar answered Oct 16 '22 05:10

ravikanth


Let's not over complicate things...:

(Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
like image 27
Zack A Avatar answered Oct 16 '22 04:10

Zack A