Home > Scripts > Powershell Script to Diff CSV Data

Powershell Script to Diff CSV Data

This script can be used to search for differences in CSV files based on a cell value and export the rows that are different to a new file. The steps are as follows:

  1. Import file1 – the file that has data to diff against.
  2. Convert the variable to an array based on the cell value you want to diff against.
  3. Import file2 – the file you want to get the diff data from.
  4. Set the export file name.
  5. For each line in file2, if the cell value is not contained in the file1 array variable, export the line to the export file.

You can copy and paste the code below or you can download the script here.

$file1 = ipcsv “.\1.csv”
$file1 = [array]$file1.No
$file2 = ipcsv “.\2.csv”
$file3 = “.\3.csv”

$file2 | %{if ($file1 -notcontains $_.No){$_ | epcsv $file3 -append -notype} }



This script is about as simple as I could make it. There are obviously a ton of things you can do with this functionality. The concept is provided to manipulate according to your needs.


These scripts have been tested and are fully functional on Windows Server 2008, Windows Server 2008 R2 and Windows 2003 Server. They are provided with no guarantee and I assume no responsibility for the use or misuse of these scripts or any issues resulting from their use.

Categories: Scripts Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: