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"

2
  • What's the desired output? Commented Nov 28, 2013 at 9:02
  • +1 for using XSLT instead of regexes. Check this: hanselman.com/blog/XSLTWithPowershell.aspx Commented Nov 28, 2013 at 10:45

1 Answer 1

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

Comments

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.