Scripts Thread, Powershell scripting output of get-counter to a csv file on XP and 2k3 in Coding and Web Development; I'm trying to develop a script which will grab performance counters and output the results into a csv file for ...
25th May 2012, 08:01 PM #1
IDG Tech News
29th May 2012, 06:16 PM #2
- Rep Power
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.Performan ceCounterSampleSet
2) Readings Timestamp CounterSamples
3) \\computer\processor(_total)\% processor time: 5/29/2012 8:59 Microsoft.PowerShell.(etc)
4) \\computer\processor(_total)\% processor time: 5/29/2012 8:59 Microsoft.PowerShell.(etc)
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?
Last edited by calamari; 29th May 2012 at 06:20 PM.
29th May 2012, 07:11 PM #3
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
29th May 2012, 10:39 PM #4
- Rep Power
By gaz003 in forum Home Access Plus+
Last Post: 22nd February 2012, 01:10 PM
By farquea in forum AV and Multimedia Related
Last Post: 4th July 2011, 09:39 AM
Last Post: 10th February 2011, 08:57 AM
By IrritableTech in forum Scripts
Last Post: 22nd October 2010, 01:11 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)