Update xml specific value using PowerShell

By : Epligam
Source: Stackoverflow.com
Question!

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"

By : Epligam


Answers

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
By : vonPryz


This video can help you solving your question :)
By: admin