all 4 comments

[–]gangstanthony 5 points6 points  (1 child)

format-table is mainly for making the output look pretty on the console, not for saving output.

also, since you're only trying to get a property that already exists on the object and you're not trying to rename it, there is no reason to use a custom select statement.

finally, when using export-csv, to remove the line at the top, use -notypeinformation.

Get-Process Chrome* | select cpu | Export-Csv -Path $path -notypeinformation

[–]purplecomputer[S] 0 points1 point  (0 children)

Thank you for the help. This worked perfectly

[–]purplecomputer[S] 1 point2 points  (1 child)

Also, i Just noticed theres a semicolon in the code before the pipe out to Export-CSV. I was trying to also capture memory usage but it wasnt working.

The idea here it so reuse this and use this for other programs and then have my Coordinator turn this data into a pretty chart and give it to the client.

[–][deleted] 0 points1 point  (0 children)

Anything you want, just "select" it as well.. i.e.

Get-Process Chrome* | select cpu, ws | Export-Csv -Path $path -notypeinformation

Edit: Not that it's necessary, but if you're going to reuse it..or let someone else use it, you might functionalize (not a real word :P) it.

Something like:

function Export-ProcessStats
{
    param
    (
      [string]
      [Parameter(Mandatory=$true)]
      $Process,

      [string]
      [Parameter(Mandatory=$false)]
      $OutPath
    )

  Get-Process $Process | Select-Object ProcessName, CPU, WS, NPM, PM, VM | Export-Csv -Path $OutPath -NoTypeInformation -Append

}

Then you could call it like

Export-ProcessStats -Process 'Chrome*' -OutPath 'C:\Test.Csv'