$Processes = @()
Get-WmiObject -Class Win32_PerfFormattedData_PerfProc_Process |
Where-Object {$_.name -notin "_Total","Idle","Memory Compression"} | ForEach-Object{
if($_.Name -match '^.*(?=#\d+)'){
$name = $Matches.Values
}
else{
$name = $_.Name
}
$cpu = $_.PercentProcessorTime/$Env:NUMBER_OF_PROCESSORS
$ws = $_.WorkingSet
if($name -notin $Processes.ProcessName){
$Processes += [pscustomobject]@{
"ProcessName" = $name
"WS" = $ws
"CPU" = $cpu
}
}
else{
$Processes | Where-Object {$_.ProcessName -eq $name} | ForEach-Object{
$_.WS += $ws
$_.CPU += $cpu
}
}
}
$Processes | Sort-Object -Property WS -Descending | Select-Object -Property ProcessName,WS -First 10 | Out-Host
$Processes | Sort-Object -Property CPU -Descending | Select-Object -Property ProcessName,CPU -First 10 | Out-Host