title: how to append data in xml using powershell
body: <p>I have below script which will create xml with data.</p>
  
  <p>======================================================================</p>
  
  <pre><code>$xmlPath = "D:\Users\admin\Desktop\Report.xml"
  $date = Get-Date -UFormat %m/%d/%Y
  
  if ( ! ( Test-Path $xmlPath ) )
  {
      # Create The XML
      $global:xmlWriter = New-Object System.XMl.XmlTextWriter($xmlPath,$Null)
      $global:xmlWriter.Formatting = "Indented"
      $global:xmlWriter.Indentation = "4"
      $global:xmlWriter.WriteStartDocument()
      $global:xmlWriter.WriteStartElement("Execution")
      $global:xmlWriter.WriteStartElement("ExecutedOn")
      $global:xmlWriter.WriteAttributeString("Date",$date)
      $global:xmlWriter.WriteStartElement("Environments")
      Foreach( $c in $cEnvironments)
      {
          $global:xmlWriter.WriteStartElement($c.Environment)
          $global:xmlWriter.WriteAttributeString("Red",$c.Red)
          $global:xmlWriter.WriteAttributeString("Green",$c.Green)
          $global:xmlWriter.WriteAttributeString("Blue",$c.Blue)
          $global:xmlWriter.WriteEndElement() #end of $c.Environment
      }
      $global:xmlWriter.WriteEndElement() #end Environments
  
      $global:xmlWriter.WriteStartElement("ClEnv")
      Foreach( $c1 in $clEnv)
      {
          $global:xmlWriter.WriteStartElement($c1.Environment)
          $global:xmlWriter.WriteAttributeString("John",$c1.John)
          $global:xmlWriter.WriteAttributeString("Mike",$c1.Mike)
          $global:xmlWriter.WriteAttributeString("Alex",$c1.Alex)
          $global:xmlWriter.WriteEndElement() #end of $c1.Environment
      }
      $global:xmlWriter.WriteEndElement() #end ExecutedOn
      $global:xmlWriter.WriteEndElement() #end execution
      $global:xmlWriter.WriteEndDocument() #end document
      $global:xmlWriter.Finalize
      $global:xmlWriter.Flush()
      $global:xmlWriter.Close()
  }
  else
  {
      here I need to append the data in existing xml with the same above info but with different value
  }
  </code></pre>
  
  <p>======================================================================
  $cEnvironments $clEnv variables are array and having related data. Now I need to re run the script next day and check if the file is already exist. this is I am doing with if command. if it is already exist then using "else" I need to append the data in existing xml with the same above info but with different values under section "Execution" like given below </p>
  
  <p>======================================================================</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;?xml-stylesheet type='text/xsl' href='style.xsl'?&gt;
  &lt;Execution&gt;
      &lt;ExecutionStarted Date="2/19/2014"&gt;
       &lt;Environments1&gt;
          &lt;Colors Red="21" Blue="14" Green="18" /&gt;
      &lt;/Environments1&gt;
      &lt;Environments2&gt;
          &lt;Names John="21" Mike="14" Alex="18" /&gt;
      &lt;/Environments2&gt;
  &lt;/ExecutionStarted&gt;
  ***&lt;ExecutionStarted Date="2/20/2014"&gt;
       &lt;Environments1&gt;
          &lt;Colors Red="2" Blue="56" Green="76" /&gt;
          &lt;Colors Cyan="31" Brown="32" Black="54" /&gt;
      &lt;/Environments1&gt;
      &lt;Environments2&gt;
          &lt;Names John="45" Mike="63" Alex="97" /&gt;
      &lt;/Environments2&gt;
  &lt;/ExecutionStarted&gt;***
  &lt;/Execution&gt;
  </code></pre>
  
  <p>Thanks.</p>