PoshCode Archive  Artifact Content

Artifact e0741cf276a60b0b2736e869e8b5d822d450abc21877ef7de358cedd299d5a05:

  • File get-highCPUprocesses.ps1 — part of check-in [aad46f5d90] at 2018-06-10 14:09:16 on branch trunk — Enumerates all CPU related tasks (filters out null CPU times) with the following properties: (user: internetrush1 size: 1319)

# 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 %'
    }
}