Aaron
Aaron

Reputation: 3325

Get-Process with total memory usage

$Processes = get-process -computername $tag1 | 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
}   

Currently, this displays memory usage in bytes, how can I change this to show something like:

76,592 KB

and also output everything that is autosized? (aligned to the left)

Upvotes: 25

Views: 137377

Answers (5)

CyberPetaNeuron
CyberPetaNeuron

Reputation: 107

On 64bit systems:

get-process | Group-Object -Property ProcessName | 
% {
    [PSCustomObject]@{
        ProcessName = $_.Name
        Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet64 -Sum).Sum / 1MB, 0)
        ProcessCount = $_.Count
    }
} | sort -desc Mem_MB | Select-Object -First 25

On 32bit systems:

get-process | Group-Object -Property ProcessName | 
% {
    [PSCustomObject]@{
        ProcessName = $_.Name
        Mem_MB = [math]::Round(($_.Group|Measure-Object WorkingSet -Sum).Sum / 1MB, 0)
        ProcessCount = $_.Count
    }
} | sort -desc Mem_MB | Select-Object -First 25

Upvotes: 4

Mike Zboray
Mike Zboray

Reputation: 40828

Format-Table can show expressions and auto-size the columns to fit the results:

On 64 bits:

get-process -computername $tag1 | Group-Object -Property ProcessName | 
    Format-Table Name, @{n='Mem (KB)';e={'{0:N0}' -f (($_.Group|Measure-Object WorkingSet64 -Sum).Sum / 1KB)};a='right'} -AutoSize

On 32 bits:

get-process -computername $tag1 | Group-Object -Property ProcessName | 
    Format-Table Name, @{n='Mem (KB)';e={'{0:N0}' -f (($_.Group|Measure-Object WorkingSet -Sum).Sum / 1KB)};a='right'} -AutoSize

Upvotes: 41

Stuart Smith
Stuart Smith

Reputation: 2051

To get the amount of memory per process used on a 64 bit windows operating system, run the following command...

 Get-Process | Sort-Object WorkingSet64 | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet64/1KB)}} | Export-Csv -Path "processes64.csv" -Delimiter ","  

Upvotes: 9

ojk
ojk

Reputation: 2542

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

Upvotes: 11

Micky Balladelli
Micky Balladelli

Reputation: 10001

Just divide by 1KB

also can use 1MB, 1GB, 1TB.

Powershell is very helpful like that.

This link should help Powershell Tip on Byte conversion

Upvotes: 8

Related Questions