在 Powershell 中创建 PerformanceCounterCategory
我正在尝试在 powershell 中运行以下脚本:
$counters = @()
$counters = $counters + [Diagnostics.CounterCreationData]::("Hit counter", "Number of total hits", [Diagnostics.PerformanceCounterType]::NumberOfItem32);
$counters = $counters + [Diagnostics.CounterCreationData]::("Hits per second", "Number of average hits per second", [Diagnostics.PerformanceCounterType]::RateOfCountsPerSecond32);
$counterCollection = [Diagnostics.CounterCreationDataCollection]::($counters);
[Diagnostics.PerformanceCounterCategory]::Create("HitCounters","Some help text",[Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $counterCollection);
当我执行此脚本时,我收到一条错误消息,指出 $counterCollection 为 null。 恐怕我对 powershell 还不够熟悉,无法找出问题所在 - 这是我构建集合的数组吗?或者 CounterCreationDataCollection 创建调用本身?
非常欢迎任何指点:)
I'm trying to run the following script in powershell:
$counters = @()
$counters = $counters + [Diagnostics.CounterCreationData]::("Hit counter", "Number of total hits", [Diagnostics.PerformanceCounterType]::NumberOfItem32);
$counters = $counters + [Diagnostics.CounterCreationData]::("Hits per second", "Number of average hits per second", [Diagnostics.PerformanceCounterType]::RateOfCountsPerSecond32);
$counterCollection = [Diagnostics.CounterCreationDataCollection]::($counters);
[Diagnostics.PerformanceCounterCategory]::Create("HitCounters","Some help text",[Diagnostics.PerformanceCounterCategoryType]::SingleInstance, $counterCollection);
When I execute this, I get an error saying $counterCollection is null.
I'm afraid I'm not yet familiar enough with powershell to sort out where this is going wrong - is it the array I'm building the Collection from? Or the CounterCreationDataCollection creation call itself?
Any pointers are more than welcome :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将静态访问器语法
::
与构造函数调用混合在一起。试试这个:You're mixing in static accessor syntax
::
with the constructor call. Try this instead: