Jump to content

Powershell scripting output of get-counter to a csv file on XP and 2k3


Recommended Posts

Posted
I'm trying to develop a script which will grab performance counters and output the results into a csv file for processing. As the target machines are running XP or server 2k3 export-counter is not available to me. :( Any tips on how I might achieve this? I'm about as green as it gets when it comes to scripting in powershell, so be gentle. Thanks!
Posted (edited)

Ok, so I've got the output going to a csv file using Export-Csv and am now trying to trim off the output I don't need.

 

Here's my line of script-

Get-Counter "\Processor(_Total)\% Processor Time" -SampleInterval 1 -MaxSamples 10 | Export-Csv c:\data.csv

 

The output I'm getting is this-

 

##-Edit: The formatting of my original post didn't come across. When viewed in Excel the file 1) is the first line, 2) the second, etc. The columns are Readings, Timestamp, and CounterSamples, with the appropriate data filling out the rest of each column.

 

1) #TYPE Microsoft.PowerShell.Commands.GetCounter.PerformanceCounterSampleSet

2) Readings Timestamp CounterSamples

3) \\computer\processor(_total)\% processor time: 5/29/2012 8:59 Microsoft.PowerShell.(etc)

1.560698633212

4) \\computer\processor(_total)\% processor time: 5/29/2012 8:59 Microsoft.PowerShell.(etc)

0.4782....

 

And so forth. What I'm trying to do now is get just the processor usage number from the first cell. I'm thinking that I can achieve this by piping the output from Get-Counter through a Where-Object on the way to Export-Csv and doing some string manipulation in there as well. I'm just not sure what object I need to get. I've tried Title and Heading to no effect. Any ideas on what object I should be trying to get or a way I can determine the appropriate object? Am I barking up the wrong tree altogether?

Edited by calamari
Posted

I think this should do what you need...

 

Get-Counter -Counter “\Processor(_Total)\% Processor Time” -SampleInterval 1 -MaxSamples 10 | Select -ExpandProperty CounterSamples | Select CookedValue | Sort CookedValue -Descending | Export-CSV -NoTypeInformation C:\Data.csv

  • Thanks 1

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...