Question: 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 ?

Answer: 
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}}

```
As i indicated by [my comment](https://stackoverflow.com/questions/17446034/how-can-i-reorganise-powershells-compare-object-output/17447708#comment113113621_17447708), [JPBlanc's answer](https://stackoverflow.com/a/17447708/5468905) has some flaws. Here's an improved one based on his code:

```bsh
$CSV1 = Import-Csv "C:\temp\f1.csv"
$CSV2 = Import-Csv "C:\temp\f2.csv"
$Diff = Compare-Object $CSV1 $CSV2 -property Header, Value
function Value-On-SideIndicator($Object, $SideIndicator) {
    $Group = $Object.Group | ? {$_.SideIndicator -eq $SideIndicator}
    if ($Group -ne $null) { $Group.Value } else { "NA" }
}
$Diff | Group-Object -Property Header | % {
    New-Object -TypeName psobject -Property @{
        Header = $_.Group[0].Value;
        newValue = Value-On-SideIndicator $_ "=>";
        oldValue = Value-On-SideIndicator $_ "<="
    }
} | Format-Table Header, oldAmount, newAmount -AutoSize

```

**Powershell 7**: (using null-coalescing operator)

```bsh
$CSV1 = Import-Csv "C:\temp\f1.csv"
$CSV2 = Import-Csv "C:\temp\f2.csv"
$Diff = Compare-Object $CSV1 $CSV2 -property Header, Value
$Diff | Group-Object -Property Header | % {
    New-Object -TypeName psobject -Property @{
        Header = $_.Group[0].Value;
        newValue = ($_.Group | ? {$_.SideIndicator -eq "=>"}).Value ?? "NA";
        oldValue = ($_.Group | ? {$_.SideIndicator -eq "<="}).Value ?? "NA"
    }
} | Format-Table Header, oldAmount, newAmount -AutoSize

```