+ Post New Thread
Results 1 to 4 of 4
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 ...
  1. #1

    Join Date
    May 2012
    Location
    Seattle
    Posts
    5
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

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

    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!

  2. #2

    Join Date
    May 2012
    Location
    Seattle
    Posts
    5
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    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)
    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?
    Last edited by calamari; 29th May 2012 at 06:20 PM.

  3. #3


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,613
    Thank Post
    250
    Thanked 2,900 Times in 2,133 Posts
    Rep Power
    828
    I think this should do what you need...

    Code:
    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

  4. Thanks to Arthur from:

    calamari (29th May 2012)

  5. #4

    Join Date
    May 2012
    Location
    Seattle
    Posts
    5
    Thank Post
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Perfect, thanks Arthur!



SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 1
    Last Post: 22nd February 2012, 01:10 PM
  2. Resolution locked to 1024 x 768 on monitor and projector
    By farquea in forum AV and Multimedia Related
    Replies: 19
    Last Post: 4th July 2011, 09:39 AM
  3. Replies: 0
    Last Post: 10th February 2011, 08:57 AM
  4. Script to add fields to a csv file
    By IrritableTech in forum Scripts
    Replies: 13
    Last Post: 22nd October 2010, 01:11 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •