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

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Disconnecting from a Windows Server 2012 R2 file sharing session on a Windows 7,8,10 machine

Event ID 64,77,1008 Certificates Events Windows Server 2008, 2008R2