Search code examples
performancepowershellmemoryperfmon

Perfmon how to get "in Use" memory


If I look in Task Manager, I can see "In Use" memory. enter image description here

I know that I can grab performance information in PerfMon, but I do not know which counter in Perfmon retrieves this value.

I want to write a PowerShell script to find out average memory usage for the past day. PerfMon is the only option that I can think of. Is there a better way to do this in PowerShell?


Solution

  • Get-Counter -Counter is the way to get performance counters in PowerShell 2+. "In use" looks like it's the rounded value of Total Memory - Available:

    [math]::Round(((((Get-Ciminstance Win32_OperatingSystem).TotalVisibleMemorySize * 1kb) - ((Get-Counter -Counter "\Memory\Available Bytes").CounterSamples.CookedValue)) / 1GB),1)