Help with creating XML in Powershell
hi i'm trying create xml. i've done little research , looks there different way's accomplish this. i'll attach have far , xml creates.
[system.xml.xmldocument]$xml=new-object system.xml.xmldocument [system.xml.xmlelement]$root = $xml.createelement("printers") $xml.appendchild($root) [system.xml.xmlelement]$node1 = $root.appendchild($xml.createelement("printer")) $node1.setattribute("id","1201") [system.xml.xmlelement]$node2 = $node1.appendchild($xml.createelement("status")) $xml.save("c:\users\user\desktop\config.xml")
it outputs:
<printers> <printer id="1201"> <status /> </printer> </printers>
what want output:
<printers> <printer id="1201"> <status>status_here_stored in varaible</status> </printer> </printers>
how output this? there better way this? help!
[system.xml.xmldocument]$xml=new-object system.xml.xmldocument [system.xml.xmlelement]$root = $xml.createelement("printers") $xml.appendchild($root) [system.xml.xmlelement]$node1 = $root.appendchild($xml.createelement("printer")) $node1.setattribute("id","1201") [system.xml.xmlelement]$node2 = $node1.appendchild($xml.createelement("status")) $node2.innertext = "something" $xml.save("c:\users\user\desktop\config.xml")after creating $node2, set innertext property
if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful.
don't retire technet
Windows Server > Windows PowerShell
Comments
Post a Comment