Forked from tanaka-takayoshi/CreatePerformanceCounter.ps1
Last active
December 6, 2016 12:24
-
-
Save cederlof/30b4cfaedf5750c757bef36193b9db64 to your computer and use it in GitHub Desktop.
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
# 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