Skip to main content

How to Get Memory Usage in PowerShell

• 2 min read
powershell memory get-process workingset

!powershell-get-memory-usage

To get memory usage in PowerShell, you can use the Get-Process cmdlet and the WorkingSet property which provides the amount of memory used by the process in bytes.

The following syntax shows how you can do it.

Get-Process | Sort-Object -Property WorkingSet -Descending | Select-Object -First 10 -Property Id, Name, @{Name='Memory (MB)';Expression={$_.WorkingSet / 1MB}}

In this script, the Get-process cmdlet retrieves all running processes on the local computer and pipes them to the Sort-Object cmdlet to sort the processes by memory usage (WorkingSet) property in descending order.

It then selects the top 10 memory-consuming processes from the sorted list. Finally, it converts the WorkingSet into megabytes.

After running this script, it will display the top 10 processes that are consuming high memory in your local computer.

Understanding Memory Properties

PowerShell provides several memory-related properties for processes:

  • WorkingSet: The amount of physical memory allocated to a process
  • VirtualMemorySize: The amount of virtual memory allocated
  • PrivateMemorySize: The amount of private memory allocated
Get-Process | Select-Object Name, @{N='WorkingSet(MB)';E={[math]::Round($_.WorkingSet/1MB,2)}}, @{N='Private(MB)';E={[math]::Round($_.PrivateMemorySize/1MB,2)}} | Sort-Object 'WorkingSet(MB)' -Descending | Select-Object -First 10

Conclusion

I hope the above article about getting memory usage in the local computer using PowerShell is helpful to you.


Process Monitoring

Data Manipulation & Filtering

Data Structures

Calculations & Formatting

Control Flow & Logic

Output & Export

Functions & Automation

Comprehensive Guides