Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
 
what do you want? Physical Disk or Physical memory? Your example shows physical memory and your question is about physical disk. –  ravikanth Jul 16 at 15:53
 
Sorry. I got them confused. I want physical memory size. I'll edit my question. Thanks! –  Fsun Jul 16 at 15:57
1  
Just out of curiosity, why do you want to avoid WMI? –  Keith Hill Jul 16 at 16:42
 
I'm avoiding WMI because it requires DCOM permissions, so a user without permissions wouldn't be able to get this information. –  Fsun Jul 16 at 17:11

2 Answers

up vote 3 down vote accepted

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()
share|improve this answer
1  
Interesting, on my system which has 8GB installed (or exactly 8192MB), system info reports that I have a total of 8155MB. I suspect that not all of the 8GB is usable by the system which could account for the difference. –  Keith Hill Jul 16 at 16:43
 
Yes. Your BIOS may be mapping certain amount of memory for BIOS shadowing functions. –  ravikanth Jul 16 at 16:44
 
So the question is - what is the OP actually after? Installed memory or total memory available for use by the computer? –  Keith Hill Jul 16 at 16:47
 
I guess installed memory. Using systeminfo.exe, you cannot actually get the accurate value but that is the only option without WMI, AFAIK. –  ravikanth Jul 16 at 16:48
 
Yes. I'm looking for installed memory. Thank you ravikanth. –  Fsun Jul 16 at 17:15

I'd like to make a note of this for people referencing in the future.

I wanted to avoid WMI because it uses a DCOM protocol, requiring the remote computer to have the necessary permissions, which could only be setup manually on that remote computer.

So, I wanted to avoid using WMI, but using get-counter often times didn't have the performance counter I wanted.

The solution I used was the Common Information Model (CIM). Unlike WMI, CIM doesn't use DCOM by default. Instead of returning WMI objects, CIM cmdlets return PowerShell objects.

CIM uses the Ws-MAN protocol by default, but it only works with computers that have access to Ws-Man 3.0 or later. So, earlier versions of PowerShell wouldn't be able to issue CIM cmdlets.

The cmdlet I ended up using to get total physical memory size was:

get-ciminstance -class "cim_physicalmemory" | % {$_.Capacity}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.