Share via


Get Process Memory Usage

Question

Thursday, May 16, 2013 10:04 AM

Hi all, I am looking to find out what the memory utilisation on one of my servers is by processes.

   

As this is a terminal server, there can be up to 50 users logged in - all using IE, Outlook, whatever...  I want to group processes by name and find the total memory usage by the process group.  So far, I have the following Powershell command:

   

get-process | Group-Object -Property ProcessName    ...which doesn't quite do what I need.  What I am aiming for is an output similar to:    Count       Name           Memory usage(Total)1           Iexplore.exe   5,000kb3           firefox.exe    70,000kb2           winword.exe     1024,475kb    Any ideas anyone???  I'm fairly new to powershell and this is way beyond my un-jedi-like abilities.Ben

All replies (6)

Thursday, May 16, 2013 11:07 AM ✅Answered | 2 votes

Hi Ben,

this should do what you need:

$Processes = get-process | 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 Mem -Value ($Process.Group|Measure-Object WorkingSet -Sum).Sum
    $Obj    
}

Greetings Malte


Thursday, May 16, 2013 11:30 AM

You, sir, are a god!


Wednesday, October 22, 2014 12:06 AM

Is it possible to go a step further and break this down per USER? I would like to know how much each of my Terminal Server users are consuming from the overall Memory of the server?


Wednesday, October 5, 2016 8:32 AM

Hi Malte,

Is there any way to sort resulting list in a way to observe 5 most memory consuming processes?

After running the script $Obj variable contains only the alphabetically last process.

Regards,

M.


Wednesday, October 5, 2016 9:17 AM

Hi Malte,

Is there any way to sort resulting list in a way to observe 5 most memory consuming processes?

After running the script $Obj variable contains only the alphabetically last process.

Regards,

M.

Please do not add unrelated questions to old, answered and closed topics.

\(ツ)_/


Wednesday, October 5, 2016 5:25 PM | 1 vote

I realize this is an old post, but this would come closer to the desired output, maybe it will be useful to someone else.

$ProcArray = @()
$Processes = get-process | Group-Object -Property ProcessName
foreach($Process in $Processes)
{
    $prop = @(
            @{n='Count';e={$Process.Count}}
            @{n='Name';e={$Process.Name}}
            @{n='Memory';e={($Process.Group|Measure WorkingSet -Sum).Sum}}
            )
    $ProcArray += "" | select $prop  
}
$ProcArray | sort -Descending Memory | select Count,Name,@{n='Memory usage(Total)';e={"$(($_.Memory).ToString('N0'))Kb"}}