top of page

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:












Sean O'Shea has more than 20 years of experience in the litigation support field with major law firms in New York and San Francisco.   He is an ACEDS Certified eDiscovery Specialist and a Relativity Certified Administrator.

​

The views expressed in this blog are those of the owner and do not reflect the views or opinions of the owner’s employer.

​

If you have a question or comment about this blog, please make a submission using the form to the right. 

Your details were sent successfully!

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

bottom of page