1

Let's say i have this xml file

<section name="AAA">
    <Item1>FALSE</Item1>
    <Item2>FALSE</Item2>
    <Item3>FALSE</Item3>
</section>
<section name="BBB">
    <Item1>FALSE</Item1>
    <Item2>FALSE</Item2>
    <Item3>FALSE</Item3>
</section>

How can I update a specific value using PowerShell ( using XPath is the right way ? )

Meaning update Item2 that under section name="BBB"

Epligam
  • 741
  • 2
  • 14
  • 36

1 Answers1

1

Assuming your XML has a root node called root and the document is loaded as $doc, the following will print modified document on console.

$doc.root.SelectSingleNode("section[@name='BBB']/Item2")."#text" = "True"
$doc.Save([console]::out)
# Output
<?xml version="1.0" encoding="ibm850"?>
<root>
  <section name="AAA">
    <Item1>FALSE</Item1>
    <Item2>FALSE</Item2>
    <Item3>FALSE</Item3>
  </section>
  <section name="BBB">
    <Item1>FALSE</Item1>
    <Item2>True</Item2>
    <Item3>FALSE</Item3>
  </section>
</root>
vonPryz
  • 22,996
  • 7
  • 54
  • 65