.png)
最も多くのメモリを使用するプロセス/ものを (Powershell で) 確認するにはどうすればよいですか?
編集: タスク マネージャーなどで物理 RAM がすべて使用されている理由が説明されない場合に、Powershell を使用して物理メモリをすべて使用しているものを特定する方法を見つけようとしています。つまり、キャッシュなどで使用されているメモリを識別する必要があります。
答え1
現在実行中のプロセスの情報を取得し、ワーキングセットのサイズで並べ替える方法は次のとおりです。
Get-Process | Sort-Object -Descending WS
その出力を変数に割り当てると、結果の配列が得られます。その後、配列の最初のメンバー(この場合はシステム.診断.プロセス物体)。
$ProcessList = Get-Process | Sort-Object -Descending WS
Write-Host $ProcessList[0].Handle "::" $Process.ProcessName "::" $Process.WorkingSet
以下は、WMI の Win32_Process プロバイダーを使用して、現在実行中のプロセスのリストからいくつかのデータ項目をダンプする、もう 1 つの簡単なスクリプトです。
$ProcessList = Get-WmiObject Win32_Process -ComputerName mycomputername
foreach ($Process in $ProcessList) {
write-host $Process.Handle "::" $Process.Name "::" $Process.WorkingSetSize
}
PID(ハンドル)、プロセス名、現在のワーキングセットサイズが表示されます。これは、WMI プロセス クラス。
答え2
最もメモリを消費するプロセスの名前を見つけるためのワンライナー
Get-Process | Sort-Object -Descending WS | select -first 1 | select -ExpandProperty ProcessName
答え3
$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;