检索性能计数器的“解释文本”

时间:2014-02-03 09:42:31

标签: powershell powershell-v3.0 performancecounter query-performance

如何通过Powershell获取Performance计数器的Explain Text字符串值。

enter image description here

我认为这将是一个计数器的属性

Get-Counter -Counter "\Processor(_Total)\% Processor Time"|gm

(Get-Counter '\logicalDisk(*)\Avg. Disk Queue Length').countersamples|gm

但事实并非如此。我找到了Lodctr /q来查询计数器和this。但是,我找不到如何获取字符串值。

1 个答案:

答案 0 :(得分:2)

如果您可以调用.net框架对象,则可以访问PerformanceCounterCategory提供的所有方法。

以下内容可帮助您入门:

$categoryName = "Processor"
$categoryInstance = "_Total"
$counterName = "% Processor Time"

# Call the static method to get the Help for the category
$categoryHelp = [System.Diagnostics.PerformanceCounterCategory]::GetCategories() | ?{$_.CategoryName -like $categoryName} | select -expandproperty  CategoryHelp

# Create an instance so that GetCounters() can be called
$pcc = new-object System.Diagnostics.PerformanceCounterCategory($categoryName)
$counterHelp = $pcc.GetCounters($categoryInstance) | ?{$_.CounterName -like $counterName} | select -expandproperty CounterHelp

$categoryHelp 
$counterHelp