• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 764
  • Last Modified:

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!!
  • 2
1 Solution
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.

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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now