I am writing powershell script to modify the xml file. I need to add a new element and add attributes to it. I tried using CreateElement and AppendChild methods but it doesnt help. Below is my sample input xml file
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>  <Subnet xmlns="http://google.com">    <Id>Network_106</Id>    <Name>Network_106</Name>    <Description>    </Description>    <NetworkAddress>173.24.106.0</NetworkAddress>    <NetworkMask>255.255.255.0</NetworkMask>  </Subnet>      I need to add the new elemetnt called DeliveryServices after a Description like below and add ID element inside it.
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>      <Subnet xmlns="http://google.com">        <Id>Network_106</Id>        <Name>Network_106</Name>        <Description>        </Description>  <DeleveryServices>    <Id>172.22.22.22</Id>    </DeleveryServices>        <NetworkAddress>173.24.106.0</NetworkAddress>        <NetworkMask>255.255.255.0</NetworkMask>      </Subnet>      I tried the below code. But it doesnt work.
  [xml]$xdoc = Get-Content "F:\Sample.xml"  $child = $xdoc.CreateElement("DeleveryServices")  $xdoc.Subnet.AppendChild($child)  $xdoc.Subnet.DeploymentServices.Id = "172.22.22.22"      I am new to powershell. Please help me.
No comments:
Post a Comment