Created
March 14, 2022 01:37
-
-
Save santisq/4c5f909f27b989c11f45e2fc99fefce7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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