Skip to content

Instantly share code, notes, and snippets.

@ranadiprony
Created February 27, 2017 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranadiprony/7d0e37cf6249fc9fc85bcb69ba25a439 to your computer and use it in GitHub Desktop.
Save ranadiprony/7d0e37cf6249fc9fc85bcb69ba25a439 to your computer and use it in GitHub Desktop.
Compare Objects 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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment