PowerShell: Check memory used by processes and virtual machines

PowerShell can be useful for many things.

There are PowerShell Cmdlets that make it fairly simple to examine the amount of memory used by processes or virtual machines.

 

Examples:

Sum of working set for all processes:

Get-Process | Measure-Object WorkingSet -Sum
"{0:N2} GB" -f ((Get-Process |
Measure-Object WorkingSet -Sum).sum / 1GB)

 

Sum of assigned memory for Hyper-V virtual machines:

Get-VM | Select-Object MemoryAssigned |
Measure-Object MemoryAssigned -Sum
"{0:N2} GB" -f ((Get-VM |
Select-Object MemoryAssigned |
Measure-Object MemoryAssigned -Sum).sum / 1GB)

 

Sorted list of processes with working set in megabytes:

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