PowerShell Genie

Find high memory processes

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

The pipeline sorts Get-Process output on WorkingSet64, the resident set in bytes as reported by the 64-bit counter, then keeps the top fifteen.

The script

1PS> Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 15 Name,Id,@{ Name = "MemoryMB"; Expression = { [math]::Round($_.WorkingSet64/1MB, 1)} }

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Name Id MemoryMB
    2 ------ ----- --------
    3 chrome 9184 464.0
    4 Code 6620 325.8
    5 pwsh 11268 75.0
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    Get-Process | Sort-Object WorkingSet64 -Descending | Select-Object -First 15 Name,Id,@{ Name = "MemoryMB"; Expression = { [math]::Round($_.WorkingSet64/1MB, 1)} }
    1. Stage 1Get-ProcessPositional values or no named parameters
    2. Stage 2Sort-Object-Descending
    3. Stage 3Select-Object-First

      How it works

      The pipeline sorts Get-Process output on WorkingSet64, the resident set in bytes as reported by the 64-bit counter, then keeps the top fifteen. A calculated property named MemoryMB converts that byte count with a 1MB divisor and rounds to one decimal so the column stays narrow enough to read.

      Adapting it

      Swap WorkingSet64 for PrivateMemorySize64 when shared pages need to be excluded from the ranking. Raise the -First value if the interesting consumer is sitting just outside the cut.

      If the result is unexpected

      MemoryMB values total far more than the RAM installed in the machine, and the per-process numbers do not match the column people are comparing against in Task Manager.

      Working set includes memory-mapped pages shared between processes, and every process holding a shared page is charged for the whole of it. Task Manager's default column shows private working set, which is why the two figures disagree. Neither is wrong; they measure different things and get quoted interchangeably.

      1. Switch the calculated property to PrivateMemorySize64 and compare against Task Manager again.
      2. Total the private figures rather than the working set values when the question is overall consumption.
      3. Read the commit charge from Win32_OperatingSystem for a machine-level view.
      4. Sample twice instead of reading one snapshot to confirm the process is genuinely growing.
      5. Check handle and thread counts on the suspect, since a leak in either shows up as memory growth.

      Validate the result

      The sum of private memory across processes lands below installed RAM, and the per-process figure lines up with the private working set column.

      Keep the check reliable

      Name the metric in the column header so nobody compares a working set figure against a private one, and use private memory for anything that feeds capacity sizing.

      Primary documentation

      Select-Object reference · Sort-Object reference · Get-Process reference

      Continue
      Genie guideFind high memory processes

      The pipeline sorts Get-Process output on WorkingSet64, the resident set in bytes as reported by the 64-bit counter, then keeps the top fifteen.