使用Powershell找出占用大量内存的资源(在64位Windows上)


9

我如何找出(在Powershell中)哪个进程/什么使用最多的内存?

编辑:我试图弄清楚如何使用Powershell来查找正在使用的所有物理内存,以防Task Manager等无法解释为什么所有物理RAM都用完了。即我需要确定缓存等使用的内存。


您在考虑哪种缓存?
squillman 2010年

磁盘缓存... Windows通常不会尝试将所有可用的物理内存用于有用的东西吗?
Andrew J. Brehm

Answers:


8

这是一种获取当前正在运行的进程的信息并按工作集大小进行排序的方法

Get-Process | Sort-Object -Descending WS

将输出分配给变量,它将为您提供结果数组,然后您只需写出数组的第一个成员(在本例中为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类的不同属性对此进行更改。


我的错。我还不够清楚。问题已编辑...
Andrew J. Brehm 2010年

1

一根衬里找到您的最高内存使用过程的名称

Get-Process | Sort-Object -Descending WS | select -first 1 | select -ExpandProperty ProcessName

0
$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;
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.