I was comparing two lengthy configuration files (XML) knowing ahead of time that there were only a couple differences between them. The code I used was as follows:
$a = Get-Content file1.xml
$b = Get-Content File2.xml
Compare-Object $a $b
My result set was not at all what I expected. Instead of being a few lines it was almost the size as my two files combined! I was confused (and a little hungry). Turning to Get-Help compare-object -full, I saw this:
-syncWindow (int)
Defines a search region where an attempt is made to re-sync the order if there is no match.
Required? false
Position? named
Default value 5
Accept pipeline input? false
Accept wildcard characters? false
I must admit that I did not find this intuitive. Looks like by default it will look 5 lines up and 5 lines down for a match before moving on. Grabbing a Snickers and Diet Coke, I took my newly acquired knowledge and tried the following:
$a = Get-Content file1.xml
$b = Get-Content File2.xml
Compare-Object $a $b -SyncWindow 50
Success!! Fat and happy, I now have the results I expected.
InputObject | SideIndicator |
driver-configuration dn="...." | "=>" |
shim-auth-id value="" | "=>" |
Enjoy!