Rahul hAs
Rahul hAs

Reputation: 23

How to get memory ( private working set ) of a process in powershell?

In task manager we can see memory ( private working set ).

My question is How to get memory ( private working set ) of a process in powershell? See image (https://i.sstatic.net/JQInb.jpg)

Upvotes: 2

Views: 8749

Answers (3)

Nabeeh Eldardery
Nabeeh Eldardery

Reputation: 1

this should work

get-process -Name iexplore | 
select name, @{Name = "Private Working Set"; Expression = { 
        $ProcessID = $_.ID; [math]::Round((gwmi Win32_PerfFormattedData_PerfProc_Process | 
                ? {$_.IDprocess -eq $ProcessID }).WorkingSetPrivate / 1mb, 0)
    }
}

Upvotes: 0

user817057
user817057

Reputation: 127

Why this not work please ?

get-process -Name iexplore | select name, @{Name="Private Working Set"; Expression = {(Get-Counter "\Process(*)\Working Set - Private").CounterSamples | Sort-Object InstanceName | Format-Table InstanceName, @{Label="PrivateWorkingSet"; Expression={$_.CookedValue / 1MB}} -AutoSize}}

Upvotes: 0

boxdog
boxdog

Reputation: 8442

One way to do it is this:

(Get-Counter "\Process(*)\Working Set - Private").CounterSamples

EDIT: Convert value to MB:

The following takes the output of Get-Counter and sorts the processes alphabetically, then creates a table with the Working Set value converted to MB:

(Get-Counter "\Process(*)\Working Set - Private").CounterSamples |
    Sort-Object InstanceName |
        Format-Table InstanceName, @{Label="PrivateWorkingSet"; Expression={$_.CookedValue / 1MB}} -AutoSize

Upvotes: 2

Related Questions