Created
December 20, 2014 02:12
-
-
Save tanaka-takayoshi/6a603d659a0a104ea0f1 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
# 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