Reputation: 141
I want to compare a part of the xml-tree of two files (GPO->Computer from a GPOReport).
$Xml1 = Get-Object $Path1
$Xml2 = Get-Object $Path2
Compare-Object ($Xml1) -DifferenceObject ($Xml2)
gives the complete differences from the file. But I want only part of the node.
Upvotes: 0
Views: 496
Reputation: 174720
Comparing trees (ie. an XML document) is a bit more complicated than comparing two lists (like the lines in two files).
It's unclear from your question how extensive a comparison you're looking for here, but if you're only interested in testing a single value or attribute between two XML documents, the easiest is probably with Select-Xml
:
$xml1 = [xml]@'
<root>
<nodegroup>
<node name="myNode">SomeValue</node>
</nodegroup>
</root>
'@
$xml2 = [xml]@'
<root>
<nodegroup>
<node name="myNode">SomeOtherValue</node>
</nodegroup>
</root>
'@
$res1,$res2 = $xml1,$xml2 |Select-Xml -XPath 'root/nodegroup/node[@name = "myNode"]'
if($res1.Node.InnerText -eq $res2.Node.InnerText){
# the inner text value of the selected node is the same in both documents
}
Upvotes: 1