PowerShell Get Memory used by a group of processes

  Powershell, Windows

Get the memory usage of a process, grouped, so you get the total.

Example; chrome, always have one process per page, use this to get the total of memory used by all of them.

$Processes = get-process chrome,iexplore | Group-Object -Property ProcessName
foreach($Process in $Processes)
{
    $Obj = New-Object psobject
    $Obj | Add-Member -MemberType NoteProperty -Name Name -Value $Process.Name
    $Obj | Add-Member -MemberType NoteProperty -Name Memory -Value ([decimal]::round((($Process.Group|Measure-Object WorkingSet -Sum).Sum)/1024/1024))
    $Obj    
}

From Laurent’s comments below, another take on this with the following code, which lists all open processes, with total memory:

ps | Group ProcessName | Select Name, @{Label="Mem";Expression={($_.group |Measure WorkingSet -sum).Sum / 1MB }} | Sort Mem

 

All other suggestions are welcome !

2 thoughts on - PowerShell Get Memory used by a group of processes

Leave a comment