Compare-Object
Compare two lists
Compare-Object -ReferenceObject $old -DifferenceObject $new
- Works on
- WindowsLinuxmacOS
- PowerShell
- 5.1 and later
- Reference
- Microsoft Learn: Compare-Object
- PowerShell 7 On Linux and macOS, diff runs the system command instead of this cmdlet. Type the full cmdlet name there.
Compares two collections. <= means only in the reference (old). => means only in the difference (new). == appears if you pass -IncludeEqual.
Try this
$old = Get-Content -Path .\old.txt
$new = Get-Content -Path .\new.txt
Compare-Object -ReferenceObject $old -DifferenceObject $new
Coming from another shell
| Shell | What you might type |
|---|---|
| bash / zsh | diff a.txt b.txt |
| cmd.exe | fc a.txt b.txt |
More in From bash and From cmd.