Powershell Command to Compare Files

All Windows users have a powerful task automation tool called Powershell which uses its own scripting language. Tonight's tip shows how to user Powershell to compare the differences and similarities between two different text files.

Go to Start . . . and search for Powershell, and then open Powershell ISE. Use the standard cd - change directory - command to change the prompt to the directory where you have two files you want to compare.

In this example you can see we have two text files listing American cities. There are a few cities which are included in both lists.

If we enter this script in Powershell, referencing the two text files, a new file named 'results.txt' will be generated.

Compare-Object -ReferenceObject (Get-Content cities1.txt) -DifferenceObject (Get-Content cities2.txt) -IncludeEqual >results.txt

The resulting file will have two columns. The second column has either an arrow or an equal sign to indicate that an individual string is in either the first or second referenced file only, or both.

Thanks to the Scripting Guys for posting this here:


Contact Me With Your Litigation Support Questions:


  • Twitter Long Shadow

© 2015 by Sean O'Shea . Proudly created with Wix.com