0

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.

2
  • 2
    What is Get-Object and what does it do? Commented Jul 4, 2019 at 13:54
  • Sorry typo....I mean Get-Content Commented Jul 5, 2019 at 8:09

1 Answer 1

1

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

My goal is to compare a GPO template xml <computer> and <user> with those we actualy imported at a domain. So I can check the GPO has the correct value's. Because those GPO's are imported on many domains.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.