I need to compare 2 CSV files, and output the differences contained in the larger one, that are not present in smaller one based on 2 headers (SiteName, PrimarySMTPAddress).
At present, i can do this using the below:
#Importing CSV
$File1 = Import-Csv -Path "C:\Data1-Large.csv"
#Importing CSV
$File2 = Import-Csv -Path "Data2.csv"
#Compare both CSV files - column PrimarySMTPAddress
$Results = Compare-Object $File1 $File2 -Property PrimarySMTPAddress -IncludeEqual
$Array = @()
Foreach($R in $Results)
{
If( $R.sideindicator -eq "==" )
{
$Object = [pscustomobject][ordered] @{
PrimarySMTPAddress = $R.PrimarySMTPAddress
"Compare indicator" = $R.sideindicator
}
$Array += $Object
}
}
#Count users in both files
($Array | sort-object username | Select-Object * -Unique).count
#Display results in console
$Array
The Problem with the above is - It will show the differences between the large CSV and the small CSV - it will spit out ALL the Primary SMTP Addresses in the large CSV.
I need to get the output to filter on the 2nd Column SiteName, so that only SiteNames that match the other CSV are enumerated (the large CSV contains 12000 ROWS vs 2500 in small one). Filtering with Compare-Object
isn't the Same, i can't see how to use Where-Object
to filter down as i would normally.
I'm new to Arrays so, would appreciate any help.
Thanks in advance.