# encoding: ascii
# api: powershell
# title: get-highCPUprocesses
# description: Enumerates all CPU related tasks (filters out null CPU times) with the following properties: 
# version: 0.1
# type: script
# author: internetrush1
# license: CC0
# x-poshcode-id: 6156
# x-archived: 2016-03-18T21:48:26
# x-published: 2016-12-29T14:44:00
#
# Name, CPUSeconds, WorkingSetMB, TotalProcessorTime, CPUPercent, and Description 
# Handy if GUI / server is unresponsive
#
    param([string]$computerName, [System.Management.Automation.PSCredential]$Credential)

    invoke-command -ComputerName $computername -Credential $Credential -ScriptBlock {

        $CPUPercent = @{
                Name = 'CurrentCPUPercent'
                Expression = {
                $TotalSec = (New-TimeSpan -Start $_.StartTime).TotalSeconds
                [Math]::Round( ($_.CPU * 100 / $TotalSec), 2)
            }
        }
        $processes = Get-Process | ? {$_.TotalProcessorTime -ne $Null} | Select-Object -Property Name, @{Name="CPUSeconds"; Expression = {($_.CPU)}},@{Name="WorkingSetMB"; Expression = {($_.WorkingSet / 1mb)}},TotalProcessorTime, $CPUPercent, Description 
    
        $processes | Sort-Object -Property CurrentCPUPercent -Descending | Out-GridView -Title 'Current Highest CPU %'
    }
}
