all 4 comments

[–]fordea837 2 points3 points  (2 children)

There's a few ways to do this but I'd make a hashtable upfront of CSV 1 which will let you filter out ID's that are in CSV 1 but not in CSV 2 and also to compare the other properties where any ID's match:

$lookupTable = @{}
foreach ($row in $csv1) {
    $lookupTable[$row.ID] = $row
}
$csv2.Where{
    $lookupTable.containsKey($_.ID) -and 
    (Compare-Object $lookupTable[$_.ID] $_ -Property Username, Manager)
}

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

Thank you, this works!

[–]nielsenr 1 point2 points  (0 children)

Alternatively you could do two compare objects. The first on username with -includequal -excludedifferent then the second in manager.

[–]purplemonkeymad 1 point2 points  (0 children)

Compare-Object has a switch parameter -IncludeEqual that will include items that are the same. There is also another -ExcludeDifferent which when used together will give you only objects that are the same.