Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

XML addition in PowerShell

$
0
0

I am trying to do some XML manipulation in PowerShell. I use online search to to find examples. I have a simple XML file I am trying to edit (Cut down to bare minimum for testing).

<?xml version="1.0" encoding="ISO-8859-1"?>
<top>
 <first>
   <property id='Prop1' value='1' />
 </first>
</top>

I read it using:
[xml]$Xml = Get-Content -Path test.xml

I am trying to add before </top>:
 <second>
   <property id='Prop2' value='2' />
 </second>

I have been able to .Clone() first and then AppendChild() but I cannot rename it. I suspect there is something easier. Same for the properties, I can Clone() and then assign $clone.value and $Clone.id, but that is probably not the right approach.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>