powershell monitor performance

Hi all experts
I've been working mostly with linux and recently begin to work with windows.
I need to poll performance counters off windows server 2003, such as cpu, memory, request per second.
The result will be inserted into a remote mysql server from which another program will grab and visualize those numbers on graph.

For instance, I do something like this
Get-Counter '\Processor(*)\% Processor Time'  

The problem is that it returns an object (in form of table). I only need the number , let's say '% CPU'.

Is there any quick way/less-system-resource-consuming way to do this?

many thanks!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris DentPowerShell DeveloperCommented:

Something like this would return those as simple strings:

Get-Counter '\Processor(*)\% Processor Time'  | `
  %{ $_.CounterSamples | %{ "$($_.InstanceName) $('{0:P2}' -f ($_.CookedValue / 100))" } }

Although you could argue that making the snippet more complex would skew the results somewhat :)

You can also get the current load from:

(Get-WMIObject Win32_Processor | Select-Object LoadPercentage).LoadPercentage

It's brief though and will only show physical processors.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
valleytechAuthor Commented:
ah THanks!!
just a dump question by the way, the second method seems to take a while to respond on screen, does it take up considerable system resources?
I will have these scripts running in background every 5 minutes.

thanks again
Chris DentPowerShell DeveloperCommented:

> does it take up considerable system resources?

No, not really. WMI is just rather slow in a fair number of cases. I'd go with whichever is faster.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.