b34*_*34r 16 powershell performance cmd performancecounter
我正在尝试将我的性能计数器组和计数器本身的验证和创建从我的Web服务移到部署期间运行的PowerShell脚本中.
可以这样做吗?或者我是否坚持使用一个简单的应用程序来构建组和计数器?
非常感谢 :)
b34*_*34r 13
刚刚想出这个,但从未发布过.
这是我的解决方案:
//save out the type name for sanity's sake
$ccdTypeName = 'System.Diagnostics.CounterCreationData'
$CounterCollection = New-Object System.Diagnostics.CounterCreationDataCollection
//create as many counters as we'd like, and add them to the collection. here's just one:
$CounterCollection.Add( (New-Object $ccdTypeName "Counter Name", "Counter Description", NumberOfItems32) )
//create the category with the counter collection
[System.Diagnostics.PerformanceCounterCategory]::Create($perfCounterCategoryName, $perfCounterVersion, [Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $CounterCollection);
Run Code Online (Sandbox Code Playgroud)