Created
February 18, 2016 00:19
-
-
Save dstreefkerk/7b802a2750744b644dfb to your computer and use it in GitHub Desktop.
A quick PowerShell function to extract Windows' list of performance counters and their corresponding IDs
This file contains 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
function Get-PerformanceCounter | |
{ | |
# Get the Performance Counters from the Registry | |
$counters = Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009' -Name 'counter' | Select-Object -ExpandProperty Counter | |
# Remove the last line | |
$counters = $counters | Select-Object -SkipLast 1 | |
# Split the string into an array | |
$counters = $counters.Split([Environment]::NewLine) | |
$counterList = @() | |
for ($x = 0; $x -lt $counters.Count; $x++) | |
{ | |
if ($x % 2 -eq 0) { | |
$counterList += New-Object -TypeName PSObject -Property @{ CounterID = [int]$counters[($x -2)];CounterName = [string]$counters[$x - 1] } | |
} | |
} | |
$counterList | Sort-Object -Property 'CounterID' | |
} | |
# Get performance counters sorted by ID | |
# Get-PerformanceCounter | Sort-Object -Property 'CounterID' | Format-Table -AutoSize | |
# Search for specific performance counters by name | |
# Get-PerformanceCounter | Where-Object {$_.CounterName -like 'file write*'} | |
# Get performance counters, sorted by name | |
Get-PerformanceCounter | Sort-Object -Property 'CounterName' | Format-Table -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment