I am trying to use the FreePhysicalMemory property from the win32_OperatingSystem class. The problem is, it usually returns a value of only a few MB. Clearly, I have more RAM avalible to me considering the fact that only Powershell is open on my computer.
I am using the following code:
$test = gwmi win32_OperatingSystem
$test.FreePhysicalMemory
Am I doing something wrong? Or do I not understand what the FreePhysicalMemory property actually returns?
Thanks for the assistance.
Can you please provide some additional details, such as your operating system, what your total physical memory is, and the actual output from the PowerShell command?
One thing to remember when using the win32_OperatingSystem class is that the values for FreePhysicalMemory and FreeVirtualMemory are returned in KB - not just bytes, so you may have have an extra division by 1024.
For example, on my computer with 4GB total physical memory (WinXP 32-bit - so the OS can only use ~3.5GB), here is the output from my PowerShell:
$test = gwmi win32_OperatingSystem
# verify the "visible" memory size to the Operating System
$test.TotalVisibleMemorySize
3652840
# check free memory
$test.FreePhysicalMemory
1872828
# divide by 1024 twice, once for KB -> MB, once for MB -> GB
($test.FreePhysicalMemory / 1024) / 1024
1.78606796264648
I have a few applications running, but that shows that I still have roughly 1.786GB of free physical memory. I verified this behavior is identical on my Win7 x64 box as well.
Here is the MSDN reference page for the Win32_OperatingSystem WMI class: http://msdn.microsoft.com/en-us/library/aa394239.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With