Skip to content

Instantly share code, notes, and snippets.

@tanaka-takayoshi
Created December 20, 2014 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tanaka-takayoshi/6a603d659a0a104ea0f1 to your computer and use it in GitHub Desktop.
Save tanaka-takayoshi/6a603d659a0a104ea0f1 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
$counterName = "Count", "Time"
$counterType = "NumberOfItems32", "NumberOfItems32"
$counterHelp = "Count", "Time"
# Delete Existing Category
$categoryCount = ([System.Diagnostics.PerformanceCounterCategory]::GetCategories() | where CategoryName -eq $categoryName).Count
If ($categoryCount -ne 0){ [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