1974Widget
asked on
How to add a column to default output of export-csv
Is there a way to do add a second column to the CSV in the following code snip? I'm putting this in a loop that goes through multiple files. I need another column so I know what file I need to look at when I get a get diff, and I can make it into a table in Excel for easy viewing.
I need the output to be one file, and am going to add Dmitri's funtion from http://dmitrysotnikov.wordpress.com/2010/01/19/export-csv-append/.
I'm comparing one master set of source files against files from different servers, which is why I need to path as a column.
compare-object -referenceobject $(get-content $sourceFile) -differenceobject $(get-content $serverFile) | export-csv -Path d:\some.csv -notype -append
I need the output to be one file, and am going to add Dmitri's funtion from http://dmitrysotnikov.wordpress.com/2010/01/19/export-csv-append/.
I'm comparing one master set of source files against files from different servers, which is why I need to path as a column.
compare-object -referenceobject $(get-content $sourceFile) -differenceobject $(get-content $serverFile) | export-csv -Path d:\some.csv -notype -append
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Just what I asked for! Thanks!
$comparison = compare-object -referenceobject $(get-content $sourceFile) -differenceobject $(get-content $serverFile)
$comparison | % {
$obj = New-Object -type PSObject
$obj | Add-Member -membertype NoteProperty -name InputObject -Value $_.InputObject
$obj | Add-Member -membertype NoteProperty -name SideIndicator -Value $_.SideIndicator
$obj | Add-Member -membertype NoteProperty -name Path -Value $source
return $obj
}
$obj | export-csv -Path d:\some.csv -notype -append