Somebody at work asked me whether its possible to get perfcounters through PowerShell. The answer, as with any question directed at this blog, is yes. Here is a little snippet below to do just that. Hint: its possible to compress this to a single line, experiment with passing in arguments to new-object it if you don't want to create a script like the one below:
param(
$CounterName=$(read-host CounterName),
$CategoryName=$(read-host CategoryName),
$InstanceName=$(read-host InstanceName),
$MachineName="."
)
## Example CounterName = "% Processor Time"
## CategoryName = "Processor"
## "_Total"
##
## get-perfcounter "Disk Transfers/sec" "PhysicalDisk" "_Total"
$counter = new-object System.Diagnostics.PerformanceCounter
$counter.CounterName = $CounterName
$counter.CategoryName = $CategoryName
$counter.InstanceName = $InstanceName
$counter.MachineName = $machinename
$counter