Reputation: 23
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
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
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
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