Friday, January 30, 2009

Compare-Object –SyncWindow parameter

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.

InputObjectSideIndicator
driver-configuration dn="....""=>"
shim-auth-id value="""=>"

Enjoy!

1 comment:

Anonymous said...

Thanks for your information, i have read it, very good!
With DVD Ripper you can transfer the entire DVD film into all popular video or audio formats.

More info you can visit: http://eztoosoft.com
DVD Ripper , DVD Ripper for Mac , DVD To iPod , DVD To iPhone , DVD To AVI for Mac , DVD To Apple TV for Mac