在 Powershell 中创建 PerformanceCounterCategory
Posted
技术标签:
【中文标题】在 Powershell 中创建 PerformanceCounterCategory【英文标题】:Creating PerformanceCounterCategory in Powershell 【发布时间】:2010-08-31 20:24:45 【问题描述】:我正在尝试在 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 为空。 恐怕我对 powershell 还不够熟悉,无法找出问题出在哪里——是我从中构建集合的数组吗?还是 CounterCreationDataCollection 创建调用本身?
任何指针都非常受欢迎:)
【问题讨论】:
【参考方案1】:您将静态访问器语法::
与构造函数调用混合在一起。试试这个:
$ccdTypeName = 'System.Diagnostics.CounterCreationDate'
$ccdcTypeName = 'System.Diagnostics.CounterCreationDataCollection'
$counters = @()
$counters += new-object $ccdTypeName "Hit counter","..."
$counters += new-object $ccdTypeName "Hits per sec","..."
$counterCollection = new-object $ccdcTypeName $counters
...
【讨论】:
以上是关于在 Powershell 中创建 PerformanceCounterCategory的主要内容,如果未能解决你的问题,请参考以下文章
powershell PowerShell:在“发送到”文件夹中创建“发送到”快捷方式。
是否可以使用 powershell 在存储帐户中创建 blob?