Get individual value filtering Get-Counter

Borgs8472
Borgs8472 used Ask the Experts™
on
So I'm trying to make a drain-stop function for my webfarm deployment script.

The overall script will be breaking the keepalive page, monitoring the active connections to the server until they drop below a given value then executing the deployment etc.

I've hit limitations working with the following code in powershell:
Get-Counter '\Web Service(_total)\Current Anonymous Users'

Open in new window

All I want to do is retrieve the value out of that, but, all my attempts at reformatting, looping through, pipelining etc are failing.

Can someone give me the appropriate functions / switches I need in order to retrieve that value please? Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Alright, been doing some work with these recently so I might be able to help.

This code will list available counters in the logicaldisk class f.ex:
Get-Counter -ListSet "logicaldisk" | Select -Expand Paths

Open in new window

This code fetches the counter on a single sample and then echoces back the values of the first one in the collection:
$Counter = Get-Counter "\LogicalDisk(*)\% Free Space" -MaxSamples 1 -SampleInterval 1
$CounterSamples = $Counter.CounterSamples

#Values from the first sample in the collection
$CounterSamples[0] | Select *

Open in new window

Commented:
Does this give you the value you need?

((Get-Counter '\Web Service(_total)\Current Anonymous Users').CounterSamples)[0].CookedValue

Author

Commented:
Perfect :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial