Created
February 27, 2017 16:19
-
-
Save ranadiprony/7d0e37cf6249fc9fc85bcb69ba25a439 to your computer and use it in GitHub Desktop.
Compare Objects using Enumerable Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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