Naive approach would look like:
$properties=@(
@{Name="Name"; Expression = {$_.name}},
@{Name="PID"; Expression = {$_.IDProcess}},
@{Name="CPU (%)"; Expression = {$_.PercentProcessorTime}},
@{Name="Memory (MB)"; Expression = {[Math]::Round(($_.workingSetPrivate / 1mb),2)}}
@{Name="Disk (MB)"; Expression = {[Math]::Round(($_.IODataOperationsPersec / 1mb),2)}}
@{Name="Path";Expression = {(Get-Process -Id $_.IDProcess).Path}}
)
$ProcessCPU = Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process |
Select-Object $properties |
Sort-Object "CPU (%)" -desc |
Select-Object -First 5 |
Format-Table -AutoSize
$ProcessCPU
If performance is crucial, join Get-Process after selecting top 5 items:
$properties=@(
@{Name="Name"; Expression = {$_.name}},
@{Name="PID"; Expression = {$_.IDProcess}},
@{Name="CPU (%)"; Expression = {$_.PercentProcessorTime}},
@{Name="Memory (MB)"; Expression = {[Math]::Round(($_.workingSetPrivate / 1mb),2)}}
@{Name="Disk (MB)"; Expression = {[Math]::Round(($_.IODataOperationsPersec / 1mb),2)}}
)
$ProcessCPU = Get-WmiObject -class Win32_PerfFormattedData_PerfProc_Process |
Select-Object $properties |
Sort-Object "CPU (%)" -desc |
Select-Object -First 5
$ProcessCPU | select *,@{Name="Path";Expression = {(Get-Process -Id $_.PID).Path}} | Format-Table
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…