I need to find discrepancies from tables in two different SQL databases. The two tables have the same headers and look like below. If the sales of a same site, same store and same register in one database source are different with the other, then insert rows that have differences into email body and send it.
Email body should look like this
I tried Compare-Object and write to csv file to see if it works but unfortunately it did not save the differences in the csv file.
Compare-Object -ReferenceObject $table1 -DifferenceObject $table2 -Property $headers -PassThru | Select-Object * -ExcludeProperty SideIndicator | Export-Csv "$OuputFile diff.csv" -NoTypeInformation
Would you please help?
Thank you.
Below code works for me
> $csvXStore = import-csv -Path "$OuputFile XStore.csv" $csvXBR =
> import-csv -Path "$OuputFile XBR.csv"
>
>
> $diff = Compare-Object -Ref $csvXStore -Diff $csvXBR -Property Date,
> Store, Register, Sales, test -PassThru |
> # Where-Object SideIndicator -eq '<=' |
> Select-Object -Property * -ExcludeProperty SideIndicator