All admins will be familiar with performance counters and their use in diagnosing issues with systems. Now you can access them in PowerShell using Get-Counter.
Get-Counter -ListSet *
will provide a list of the counters available on your system. This is rather a lot of information so we can use
Get-Counter -ListSet * | Select CounterSetName
to just show us the names of the sets of counters. Everyone wants to know how their processor is doing so we can see what is available in the processor set
PS> Get-Counter -ListSet processor
CounterSetName : Processor
MachineName : .
CounterSetType : MultiInstance
Description : The Processor performance object consists of counters that measure aspects of processor activity The processor is the part of the computer that performs arithmetic and logical computations, initiates operations on peripherals, and runs the threads of processes. A computer can have multiple processors. The processor object represents each processor as an instance of the object.
Paths : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Processor(*)\Interrupts/sec...}
PathsWithInstances : {\Processor(0)\% Processor Time, \Processor(1)\% Processor Time, \Processor(_Total)\% Processor Time, \Processor(0)\% User Time...}
Counter : {\Processor(*)\% Processor Time, \Processor(*)\% User Time, \Processor(*)\% Privileged Time, \Processor(*)\Interrupts/sec...}
We need the counter paths to be able to use them
PS> (Get-Counter -ListSet processor).Paths
\Processor(*)\% Processor Time
\Processor(*)\% User Time
\Processor(*)\% Privileged Time
\Processor(*)\Interrupts/sec
\Processor(*)\% DPC Time
\Processor(*)\% Interrupt Time
\Processor(*)\DPCs Queued/sec
\Processor(*)\DPC Rate
\Processor(*)\% Idle Time
\Processor(*)\% C1 Time
\Processor(*)\% C2 Time
\Processor(*)\% C3 Time
\Processor(*)\C1 Transitions/sec
\Processor(*)\C2 Transitions/sec
\Processor(*)\C3 Transitions/sec
So using
PS> Get-Counter -Counter "\Processor(*)\% Processor Time"
gives samples like this – once every second.
05/01/2009 20:15:56 \\pcrs2\processor(0)\% processor time :
7.24578223708658
\\pcrs2\processor(1)\% processor time :
1.4486436269045
\\pcrs2\processor(_total)\% processor time :
4.34721293199554
Notice that I get a value for each processor & the total.
We can control the number of samples and the interval with –MaxSamples and –SampleInterval respectively. Sample interval is in seconds.
Best of all by using the –computername parameter we can access counters on remote machines. This will give us a quick way of checking on our servers.
One more reason PowerShell should be always open and ready to use.
One thing I must do is try this with PowerGadgets……
alternatively a simple WPF application with some counters updating would be cool. Hmm something to think about.

