Home » How to Get Memory Usage in PowerShell

How to Get Memory Usage in PowerShell

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}}

Output:

PowerShell get memory usage
PowerShell get memory usage

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.

Conclusion

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

You can find more topics about Active Directory tools and PowerShell basics on the ActiveDirectoryTools home page.