Skip to content

Instantly share code, notes, and snippets.

@santisq
Created March 14, 2022 01:37
Show Gist options
  • Select an option

  • Save santisq/4c5f909f27b989c11f45e2fc99fefce7 to your computer and use it in GitHub Desktop.

Select an option

Save santisq/4c5f909f27b989c11f45e2fc99fefce7 to your computer and use it in GitHub Desktop.
(Get-Counter '\Processor(*)\% Processor Time').CounterSamples | Select-Object @(
@{
Name = 'Path'
Expression = { $_.Path.TrimStart('\').ToUpper() }
}
'InstanceName'
@{
Name = 'Load'
Expression = { ($_.CookedValue / 100).ToString('P') }
}
)
function CalcUsage {
param([int64[]]$Usage)
([System.Linq.Enumerable]::Sum($Usage) / 100 / $env:NUMBER_OF_PROCESSORS).ToString('P')
}
(Get-Counter '\Process(*)\% Processor Time' -EA 0 -).Countersamples |
Sort-Object CookedValue -Descending |
Group-Object InstanceName |
ForEach-Object {
if($_.Name -eq '_total') { return }
[pscustomobject]@{
ProcessInstances = $_.Count
ProcessName = $_.Name
Usage = CalcUsage $_.Group.CookedValue
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment