Given that you want to find the new lines between two .csv files, you can use Compare-Object
.
$a = Import-Csv -Path C:\Users\subhatnagar\Desktop\old.csv
$b = Import-Csv -Path C:\Users\subhatnagar\Desktop\new.csv
Compare-Object -ReferenceObject $a -DifferenceObject $b | Select-Object -ExpandProperty InputObject | Export-Csv C:\Users\subhatnagar\Desktop\difference.csv -NoTypeInformation
Explanation of the Command:
Compare-Object -ReferenceObject $a -DifferenceObject $b
- Find the Difference between to Objects
Select-Object -ExpandProperty InputObject
- Show only the different Objects and not the Indicator of Compare-Object
Export-Csv -NoTypeInformation
- Stores the piped values into a .csv file without Type-Header.
If you only want to store the difference in a variable just delete the Export-Csv
part:
$green = Compare-Object -ReferenceObject $a -DifferenceObject $b | Select-Object -ExpandProperty InputObject