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?
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.
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.
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()
Let's not over complicate things...:
(Get-CimInstance Win32_PhysicalMemory | Measure-Object -Property capacity -Sum).sum /1gb
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