I’m looking to use PowerShell to alter XML. I haven’t been able to copy XML using XPath. I can load the XML, but I can’t figure out how to list the XML with an XPath and create another XML file with what I retrieve.
$doc = new-object "System.Xml.XmlDocument"
$doc.Load("XmlPath.xml")
Also, how would you add the removed XML to another XML file?
If you’re using PowerShell 2.0 you can use the new Select-Xml cmdlet to select xml based on an XPath expression e.g.:
To remove nodes:
Then to save to file: