Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cederlof/30b4cfaedf5750c757bef36193b9db64 to your computer and use it in GitHub Desktop.
Save cederlof/30b4cfaedf5750c757bef36193b9db64 to your computer and use it in GitHub Desktop.
# Perfmon Name and Help
$categoryName = "MyAppPerformance"
$categoryHelp = "MyApp"
$categoryType = [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance
# Fix it by Index, three arrays where indices must match
$counterName = "Count", "Time"
$counterType = "NumberOfItems32", "NumberOfItems32"
$counterHelp = "Count", "Time"
# Delete Existing Category
$exists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
if ($exists){
[System.Diagnostics.PerformanceCounterCategory]::Delete($categoryName)
}
# Create Collection
$objCCDC = New-Object System.Diagnostics.CounterCreationDataCollection
0..($counterName.count -1) `
| %{
$objCCD = New-Object System.Diagnostics.CounterCreationData
$objCCD.CounterName = $counterName[$_]
$objCCD.CounterType = $counterType[$_]
$objCCD.CounterHelp = $counterHelp[$_]
$objCCDC.Add($objCCD) > $null
}
$objCCDC | Format-Table -AutoSize | Out-String | %{[Console]::WriteLine($_)}
# Perfmon Execute
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryHelp, $categoryType, $objCCDC) | Out-String | %{[Console]::WriteLine($_)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment