Skip to content

Instantly share code, notes, and snippets.

@dstreefkerk
Created February 18, 2016 00:19
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dstreefkerk/7b802a2750744b644dfb to your computer and use it in GitHub Desktop.
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
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