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.