Monday, 27 February 2017

Compare-Object Using Enumerable Class

## Will list the content present in Both the files
$file1 = import-csv -Path "C:\ps\output\obj1.csv"
$file2 = import-csv -Path "C:\ps\output\obj2.csv"
[linq.enumerable]::intersect( [object[]]($file1.name), [object[]]($file2.name) ) | Export-Csv -NoTypeInformation -Path "C:\ps\result\result.csv"
## will list the content present either in one of the files but not in both
$file1 = import-csv -Path "C:\ps\output\obj1.csv"
$file2 = import-csv -Path "C:\ps\output\obj2.csv"
$res = [Collections.Generic.HashSet[String]]( [string[]]($file1.name) )
$res.SymmetricExceptWith( [string[]]($file2.name) )
$res | Export-Csv -NoTypeInformation -Path "C:\ps\result\result.csv"
## For union operation, you can try like this
[system.linq.enumerable]::union([object[]](1,2,3),[object[]](2,3,4))