Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can Powershell on Windows 7 diff two files on the hard drive?

Sometimes a text compare is helpful, but otherwise just telling whether a file is identical to another file is helpful. thanks.


on UNIX, it is

diff file1.dat file2.dat

On Powershell, if I create file1.txt, containing the content "hello" and copy this file to file2.txt, and type

diff file1.txt file2.txt

the result is

InputObject                                                 SideIndicator
-----------                                                 -------------
file2.txt                                                   =>
file1.txt                                                   <=

if I change the content of file2.txt to "hello world" and diff again, the result of diff'ing is the same.

share|improve this question
up vote 7 down vote accepted

Edit: Apparently there is a built in alias so this works too:

diff $(Get-Content C:\file1.txt) $(Get-Content C:\file2.txt)

You can do this:

Compare-Object $(Get-Content c:\file1.txt) $(Get-Content c:\file2.txt)

This is some sample output:

InputObject                             SideIndicator
-----------                             -------------
This is a line in file 2                =>
This is a line in file 1                <=

You can also do -excludeDifferent to only show the lines that are the same or -includeEqual to include the lines that are the same.

share|improve this answer
please see update above – 太極者無極而生 Oct 26 '09 at 20:16
Yea, you're right. You need to use $(Get-Content filename) for it to diff properly. I'll update. – djhowell Oct 26 '09 at 20:45
For what it's worth, it's a really slow way to do diffs ;) You should at least add a separator parameter like this to speed up the get-content cmdlets: -Separator ([char]0x222) – Jaykul Oct 27 '09 at 1:29
diff (cat C:\file1.txt) (cat C:\file2.txt) for the lazy. – sh54 Feb 10 '12 at 10:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.