-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateNewCounter.ps1
33 lines (24 loc) · 1.11 KB
/
CreateNewCounter.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$categoryName = "My custom counter set"
$categoryHelp = "A Performance object for testing"
$categoryType = [System.Diagnostics.PerformanceCounterCategoryType]::MultiInstance #
$categoryExists = [System.Diagnostics.PerformanceCounterCategory]::Exists($categoryName)
If (-Not $categoryExists)
{
$objCCDC = New-Object System.Diagnostics.CounterCreationDataCollection
$objCCD1 = New-Object System.Diagnostics.CounterCreationData
$objCCD1.CounterName = "My custom metric"
$objCCD1.CounterType = "NumberOfItems32"
$objCCD1.CounterHelp = "My custom metric"
$objCCDC.Add($objCCD1) | Out-Null
[System.Diagnostics.PerformanceCounterCategory]::Create($categoryName, $categoryHelp, $categoryType, $objCCDC) | Out-Null
}
## Create new instance
$Counter1 = New-Object System.Diagnostics.PerformanceCounter($categoryName, "My custom metric", "My custom metic instance", $false)
# Set a value
$Counter1.RawValue = 1024
$Counter1.RawValue
$Counter1.Disposed
## check result
Get-Counter -Counter "\My custom counter set(*)\My custom metric"
## clean-up
[System.Diagnostics.PerformanceCounterCategory]::Delete("$categoryName")