I have been trying to code the powershell script to compare 2 csv files for some time. Found a scratch of the script in this forum, but it does not work the way I want. We are exporting our SKU's every week and I need to compare if there are any new SKUS in the new file.
I tried to run the script and it works, but only for a small range of rows. When I tried to compare the real file with 5k rows, it unfortunately failed. The output had almost 3k rows which is nonsense because we didnt add that many rows in one week.
Clear-Host
$csv1 = Import-Csv "SKU_export_2019-04-01.csv" # NEW FILE
$csv2 = Import-Csv "SKU_export_2019-03-25.csv" # OLD FILE
$end = $csv1.Count
$count = 0
$diffobj = @()
do{
if($csv1.SKU[$count] -ne $csv2.SKU[$count]){
$diffobj += $csv1[$count]
}
$count++
}until($count -eq $end)
$diffobj | export-csv C:\xampp\htdocs\diff\difference.csv -NoTypeInformation
The expected result should be an output with all the differences in the new file.