
Firstly, the default behaviour collects the differences until the entire object (file = array of strings) has been checked thus losing the information regarding the position of the differences and obscuring which differences are paired (and there is no concept of line number for a SET of strings). This severely limits its usefulness for comparing text files for differences.

2 sets are equal if they have the same member items irrespective of order or duplications. UNORDERED collections without duplicates. if the objects are collections then they are treated as SETS (see help compare-object), i.e. Most notably, it does not automatically work with Unicode, treating the 0 MSB of ASCII characters as a line terminator so the file becomes a sequence of 1 character lines use the /U option to specify BOTH files are Unicode, WinXP onwards) and it also has a hard line buffer size of 128 characters (128 bytes ASCII, 256 bytes Unicode) so long lines get split up and compared separately.Ĭompare-object is designed to determine if 2 objects are member-wise identical.

Being a (very) old DOS utility, it does have a few limitations. It also has some useful control options (text/binary, case sensitivity, line numbers, resynchronisation length, mismatch buffer size) and provides exit status (-1 bad syntax, 0 files same, 1 files differ, 2 file missing). compares lines sequentially, showing the actual differences and trying to re-synchronise (if the differing sections have different lengths). Powershell has some nice features, but there are some things it should just not try to do for me.įc.exe is better for text comparing since it designed to work like *nix diff, i.e. Mainly because Powershell doesn't understand arguments which are run together and typing, for example "rm -Force -Recurse" is a lot more effort than "rm -rf". If anyone is interested, having GnuWin32 installed, I also include the following in my powershell profile: remove-item alias:rm The -force argument is required because Powershell is quite precious about this particular inbuilt alias. edit %USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1Īdd the line remove-item alias:diff -force.The solution for anyone looking for a sane output is For another, the difference indicator is on the right, far from the content - it's a readability nightmare. For one thing, you have to hold it's hand in actually reading files (with gc / get-content).

As others have noted, if you were expecting a unix-y diff output, using the powershell diff alias would let you down hard.
