如何在PowerShell中获取进程的内存(私有工作集)?

时间:2018-06-07 07:34:16

标签: windows powershell memory memory-management process

在任务管理器中,我们可以看到内存(私有工作集)。

我的问题是如何在PowerShell中获取进程的内存(私有工作集)?见图 (https://i.stack.imgur.com/JQInb.jpg

3 个答案:

答案 0 :(得分:1)

这样做的一种方法是:

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

编辑:将值转换为MB:

以下获取Get-Counter的输出并按字母顺序对进程进行排序,然后创建一个表,其中Working Set值转换为MB:

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

答案 1 :(得分:0)

为什么这不起作用?

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}}

答案 2 :(得分:0)

这应该有效

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)
    }
}