Skip to content

Free memory

Terminal window
$os = Get-CimInstance Win32_OperatingSystem
[pscustomobject]@{
TotalGB = [math]::Round($os.TotalVisibleMemorySize / 1MB, 1)
AvailableGB = [math]::Round($os.FreePhysicalMemory / 1MB, 1)
UsedPercent = [math]::Round((1 - $os.FreePhysicalMemory / $os.TotalVisibleMemorySize) * 100)
}

TotalVisibleMemorySize and FreePhysicalMemory come in kilobytes, so dividing by 1MB (1,048,576) gives gigabytes.

Terminal window
Get-Process |
Sort-Object WorkingSet64 -Descending |
Select-Object -First 10 Name, Id,
@{ n = 'MemoryMB'; e = { [math]::Round($_.WorkingSet64 / 1MB) } }

The working set is the physical RAM the process is using right now.

Total memory per program (adds up all the processes with the same name, such as every Chrome tab):

Terminal window
Get-Process | Group-Object Name | ForEach-Object {
[pscustomobject]@{
Name = $_.Name
Count = $_.Count
MemoryMB = [math]::Round(($_.Group | Measure-Object WorkingSet64 -Sum).Sum / 1MB)
}
} | Sort-Object MemoryMB -Descending | Select-Object -First 10
Terminal window
while ($true) {
$os = Get-CimInstance Win32_OperatingSystem
"{0:HH:mm:ss} available: {1:N1} GB" -f (Get-Date), ($os.FreePhysicalMemory / 1MB)
Start-Sleep -Seconds 2
}

Stop it with Ctrl+C.

Terminal window
Get-CimInstance Win32_PageFileUsage | Select-Object Name, AllocatedBaseSize, CurrentUsage, PeakUsage

Values are in MB. If CurrentUsage stays high, the machine is short of RAM.