Jan 31 2022 10:31 PM
$baseServer="C:\Store\PS\referrencexml.xml"
$Server2Compare="C:\Store\PS\differencexml.xml"
$boutput = Compare-Object -ReferenceObject (Get-Content -Path "$baseServer") -DifferenceObject (Get-Content -Path "$Server2Compare")
Above command shows the difference between two files in the below format(Output1), but I need to display the difference in side by side like Output2. So, if someone could help me with an idea or sample code/script to get the output in two different column side by side, it will be very helpful.
Output1:
Input Object Side Indicator
<genre></genre> =>
<genre>Fantasy</genre> <=
Output 2:
Reference File Difference File
<genre></genre> <genre>Fantasy</genre>
Feb 01 2022 12:40 AM
Not sure if that's possible, but it's PowerShell so anything is ;), but you could try this to show the differences in the second file
$original = Compare-Object $XML1 $XML2 | Where-Object{ $_.SideIndicator -eq "=>" } | ForEach-Object{ $_.InputObject }
Feb 01 2022 12:55 AM
Feb 01 2022 07:28 AM
I did some more experimenting ... hope the code comments explain what is being done
# set up two xml variables
# the equivalent for you would be [xml] (get-content <xmlfilepath>)
[xml]$doc1 = @"
<geography>
<country>
<name>UK</name>
<capital>London</capital>
</country>
<country>
<name>France</name>
<capital>Paris</capital>
</country>
</geography>
"@
[xml]$doc2 = @"
<geography>
<country>
<name>Germany</name>
<capital>Berlin</capital>
</country>
<country>
<name>UK</name>
<capital>London</capital>
</country>
<country>
<name>Italy</name>
<capital>Rome</capital>
</country>
</geography>
"@
# because the two variables are [xml] data type we can now use xml notation to reference the parts we want to compare - here compare country names
compare-object -referenceobject $doc1.geography.country.name -differenceobject $doc2.geography.country.name
<#
InputObject SideIndicator
----------- -------------
Germany =>
Italy =>
France <=
#>
# here compare country capitals
compare-object -referenceobject $doc1.geography.country.capital -differenceobject
$doc2.geography.country.capital
<#
InputObject SideIndicator
----------- -------------
Berlin =>
Rome =>
Paris <=
#>
# now there is also the Select-Xml which is a bit less specific
$Doc1Capitals = Select-Xml -Xml $doc1 -XPath "//capital"| foreach {$_.node.InnerXML}
$Doc2Capitals = Select-Xml -Xml $doc2 -XPath "//capital"| foreach {$_.node.InnerXML}
# so when we compare those varaibles we can get the same output
compare-object $Doc1Capitals $Doc2Capitals
<#
InputObject SideIndicator
----------- -------------
Berlin =>
Rome =>
Paris <=
#>
hope this gives you a boost but I fear you are working with complex XML and the parsing and evaluation will be difficult
Feb 01 2022 10:12 PM
Feb 01 2022 10:17 PM
Feb 01 2022 10:24 PM