user130268
user130268

Reputation: 1361

Is it possible to get performance counter description using Powershell command get-counter?

On Windows, we can easily get the description of a performance counter by using the perfmon utility. Take a look at the description section in below snapshot.

enter image description here

Is it possible to get this info from Powershell's get-counter cmdlet?

Upvotes: 3

Views: 813

Answers (2)

Ross
Ross

Reputation: 1

I ended up getting this working using these two methods, one for SingleInstance and one for MultiInstance. MultiInstance needed you to feed it an instance name to then query the counters and thus help/descriptions.

# Multi Instance
$categories = [System.Diagnostics.PerformanceCounterCategory]::GetCategories()
$category = $categories | where { $_.CategoryName -eq 'Processor'}
$instances = $category.GetInstanceNames()
$counters = $category.GetCounters($instances[0])


# Single Instance
$categories = [System.Diagnostics.PerformanceCounterCategory]::GetCategories()
$category = $categories | where { $_.CategoryName -eq 'System'}
$counters = $category.GetCounters()

You can then match your counter name onto the CounterName field to pull the CounterHelp for a SingleInstance counter.

CategoryName     : System
CounterHelp      : Floating Emulations/sec is the rate of floating emulations performed by the system.  This counter displays the difference between the values observed in the last two samples, divided by
                   the duration of the sample interval.
CounterName      : Floating Emulations/sec
CounterType      : RateOfCountsPerSecond32
InstanceLifetime : Global
InstanceName     :
ReadOnly         : True
MachineName      : .
RawValue         : 0
Site             :
Container        :

And effectively the same for MultiInstance such as Processor, though makes the assumption that it's the same for every instance. I'm sure this can be handled better but for generating the templates I needed it worked well.

CategoryName     : Processor
CounterHelp      : C3 Transitions/sec is the rate that the CPU enters the C3 low-power idle state. The CPU enters the C3 state when it is sufficiently idle and exits this state on any interrupt. This counter
                   displays the difference between the values observed in the last two samples, divided by the duration of the sample interval.
CounterName      : C3 Transitions/sec
CounterType      : RateOfCountsPerSecond64
InstanceLifetime : Global
InstanceName     : 22
ReadOnly         : True
MachineName      : .
RawValue         : 0
Site             :
Container        :

Upvotes: 0

trebleCode
trebleCode

Reputation: 2328

It appears that information is stored in the registry at (for English):

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009 in the multi-string key Help

So since PowerShell can use the Registry as a Provider, yes you can get this information technically although it's a bit ugly:

(Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\009").Help

That will pull all the text from the help entry, which you can then filter through with pipes/Select-String/various string methods, Where clauses/etc.

Upvotes: 3

Related Questions