创造&在powershell脚本或命令行中编辑性能计数器

时间:2010-08-31 00:10:38

标签: performance powershell cmd performancecounter

我正在尝试移动验证&从我的Web服务和部署期间运行的PowerShell脚本中创建我的性能计数器组和计数器本身。

可以这样做吗?或者我是否坚持使用一个简单的应用程序来构建群组&计数器?

非常感谢:)

1 个答案:

答案 0 :(得分: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); 
相关问题