instead of looking at the Task Manager and trying to find who is using the most, you can use this PowerShell script:
$h = @{}Notice that this gives you the actual RAM usage which might not be what you are looking for, as recent users probably using more RAM than not recent ones.
get-wmiobject win32_process | foreach {
$u = $_.getowner().user;
if ( $u -ne $null)
{
if ( !$h.ContainsKey($u) )
{
$h.add( $u, $_.WS);
}
else
{
$h.item($u) = $h.item($u) + $_.WS;
}
}
}
$h.GetEnumerator() | sort value -desc
If you want to know the total usage of Virtual Memory - replace "WS" with "VM".
3 comments:
My friend, can you tellme how to show the results yn MB or GB?
Thank you for that piece of code, it was exactly what I needed for my environment
I'm sending a new change to show the memory in MB:
$h = @{}
get-wmiobject win32_process | foreach {
$u = $_.getowner().user;
if ( $u -ne $null)
{
if ( !$h.ContainsKey($u) )
{
$h.add( $u, $_.WS);
}
else
{
$h.item($u) = $h.item($u) + $_.WS;
}
}
}
$h.GetEnumerator() | select-object name,@{name='MemoryUsage';expression={$_.value/1mB}}|sort name
Post a Comment