How to compare two text files using Powershell?

Hello, I haven't used powershell a lot, so I am new to this and I would like to know how can I compare two (2) text files using powershell and get the difference between two files?


Asked by:- vikas_jk
: 1313 At:- 5/11/2022 1:58:07 PM
Windows Powershell

1 Answers
profileImage Answered by:- manish_jk

You can simply use compare-object command

compare-object (get-content one.txt) (get-content two.txt)

or you can use it's alias

diff (cat file1) (cat file2)

Diff and cat are just aliases for Compare-Object and Get-Content in PowerShell.


If you don't want to use Powershell, as sometime it doesn't show long lines differences easily, you can use WinMerge which is good tool to check difference between two files.

At:- 5/11/2022 2:06:19 PM
thanks for quick answer, I will check WinMerge but I think using powershell is better for now. 0
By : vikas_jk - at :- 5/11/2022 2:07:32 PM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use