问题
I'm comparing 2 CSV with the compare-object cmdlet :
Compare-object $CSV1 $CSV2 -property Header, Value -passthru | sort-object Header
After comparing 2 CSVs, i ended up with the following output :
Header Value SideIndicator
------- ----- -------------
String1 Value 1 <=
String1 Value 2 =>
String2 Value 3 <=
String2 Value 4 =>
String3 Value 5 =>
String4 Value 6 <=
I'd like to reorganise it to the following format
Header1 Old Value New Value
------ --------- ---------
String1 Value 1 Value 2
String2 Value 3 Value 4
String3 NA Value 5
String4 Value 6 NA
Is that doable in powershell ?
回答1:
You can try this :
$a = Compare-Object (Import-Csv 'C:\temp\f1.csv') (Import-Csv 'C:\temp\f2.csv') -property Header,Value
$a | Group-Object -Property Header | % { New-Object -TypeName psobject -Property @{Header=$_.name;newValue=$_.group[0].Value;oldValue=$_.group[1].Value}}
来源:https://stackoverflow.com/questions/17446034/how-can-i-reorganise-powershells-compare-object-output