我如何找出(在Powershell)什么过程/什么使用最多的内存?
编辑:我想弄清楚如何使用Powershell找出什么是使用所有的物理内存的情况下,任务pipe理器等无法解释为什么所有的物理RAM用完了。 也就是说,我需要识别高速caching等使用的内存
这里有一个获取当前正在运行的进程信息的方法,并按工作集大小进行sorting
Get-Process | Sort-Object -Descending WS
将该输出分配给一个variables,它会给你一个结果数组,然后你可以写出数组的第一个成员(在这种情况下,它将是一个System.Diagnostics.Process对象)。
$ProcessList = Get-Process | Sort-Object -Descending WS Write-Host $ProcessList[0].Handle "::" $Process.ProcessName "::" $Process.WorkingSet
这里有另外一个快速和肮脏的脚本来使用WMI的Win32_Process提供程序从当前正在运行的进程列表中转储一些数据项:
$ProcessList = Get-WmiObject Win32_Process -ComputerName mycomputername foreach ($Process in $ProcessList) { write-host $Process.Handle "::" $Process.Name "::" $Process.WorkingSetSize }
这将列出PID(句柄),进程名称和当前工作集大小。 您可以使用WMI Process类的不同属性来更改它。
一个class轮find您最高的内存使用过程的名称
Get-Process | Sort-Object -Descending WS | select -first 1 | select -ExpandProperty ProcessName
$scripthost = Read-Host "Enter the Hostname of the Computer you would like to check Memory Statistics for" "" "" "===========CPU - Top 10 Utilization List===========" gwmi -computername $scripthost Win32_PerfFormattedData_PerfProc_Process| sort PercentProcessorTime -desc | select Name,PercentProcessorTime | Select -First 10 | ft -auto "===========Memory - Top 10 Utilization List===========" gwmi -computername $scripthost Win32_Process | Sort WorkingSetSize -Descending | Select Name,CommandLine,@{n="Private Memory(mb)";Expression = {[math]::round(($_.WorkingSetSize / 1mb), 2)}} | Select -First 10 | Out-String #gwmi -computername $scripthost Win32_Process | Sort WorkingSetSize -Descending | Select Name,CommandLine,@{n="Private Memory(mb)";e={$_.WorkingSetSize/1mb}} | Select -First 10 | Out-String #$fields = "Name",@{label = "Memory (MB)"; Expression = {[math]::round(($_.ws / 1mb), 2)}; Align = "Right"}; "===========Server Memory Information===========" $fieldPercentage = @{Name = "Memory Percentage in Use (%)"; Expression = { “{0:N2}” -f ((($_.TotalVisibleMemorySize - $_.FreePhysicalMemory)*100)/ $_.TotalVisibleMemorySize)}}; $fieldfreeram = @{label = "Available Physical Memory (MB)"; Expression = {[math]::round(($_.FreePhysicalMemory / 1kb), 2)}}; $fieldtotalram = @{label = "Total Physical Memory (MB)"; Expression = {[math]::round(($_.TotalVisibleMemorySize / 1kb), 2)}}; $fieldfreeVram = @{label = "Available Virtual Memory (MB)"; Expression = {[math]::round(($_.FreeVirtualMemory / 1kb), 2)}}; $fieldtotalVram = @{label = "Total Virtual Memory (MB)"; Expression = {[math]::round(($_.TotalVirtualMemorySize /1kb), 2)}}; $memtotal = Get-WmiObject -Class win32_OperatingSystem -ComputerName $scripthost; $memtotal | Format-List $fieldPercentage,$fieldfreeram,$fieldtotalram,$fieldfreeVram,$fieldtotalVram;