Diff Two Text Files with Compare-Object
Built-in PowerShell comparison that lists lines unique to each file.
01Command
$ Compare-Object (Get-Content a.txt) (Get-Content b.txt) -IncludeEqual:$false02What it does
Compare-Object compares the line arrays produced by Get-Content and prints lines with a SideIndicator: => means the line is only in the second file, <= only in the first. Adding -CaseSensitive matters for config files, and -SyncWindow 0 forces strict line-position comparison instead of set matching. For a full unified-diff feel, pipe the result through Format-Table or select LineInputObject.
03Risk
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Compare-Object (Microsoft.PowerShell.Utility)Evidence: Documents Compare-Object with => (present only in reference object) and <= (present only in difference object) side indicators.
Last verified: 2026-09-17 · Category: Files & Folders
06Related solutions
Search inside text files and logs with regex, returning file, line number and match.
Create or update a .zip from any files or folder contents straight from PowerShell.
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.