Skip to main content

Get CPU Usage for a Process Using Get-Counter and PowerShell.

# ##############################################################
# Powershell: Get CPU Usage for a Process Using Get-Counter
# http://www.adminarsenal.com/admin-arsenal-blog/powershell-get-cpu-usage-for-a-process-using-get-counter/
# ##############################################################

$ProcessName = "iexplore"

$CpuCores = (Get-WMIObject Win32_ComputerSystem).NumberOfLogicalProcessors
$Samples = (Get-Counter "\Process($Processname*)\% Processor Time").CounterSamples
$Samples | Select InstanceName, @{Name="CPU %";Expression={[Decimal]::Round(($_.CookedValue / $CpuCores), 2)}}