title: Powershell XML Export-csv not appending a Hash
body: <p>I am fairly new to Powershell, I have rather weird xml according to me, My main objective is to convert the XML into CSV, where it ll be further used to sync to a database.
  I have used the Powershell code to extract the xml into a hash.
  Now I have problem converting them into CSV. The Export-csv writes only the last entry in the hash. Not sure why this, i checked few other forums, they say the -append feature in Export-csv is with powershell 3.0 only, i am using 1.0.. </p>
  
  <p><strong>can you help me out of this ?</strong></p>
  
  <p>XML :</p>
  
  <pre><code>&lt;catalog&gt;
  &lt;segment&gt;
  &lt;segmentname&gt;Batch&lt;/segmentname&gt;
  &lt;hosts&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist17&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist18&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist19&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist20&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;/hosts&gt;
  &lt;/segment&gt;
  &lt;segment&gt;
  &lt;segmentname&gt;Custom S2&lt;/segmentname&gt;
  &lt;hosts&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist21&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist22&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;/hosts&gt;
  &lt;/segment&gt;
  &lt;segment&gt;
  &lt;segmentname&gt;eCommerce&lt;/segmentname&gt;
  &lt;hosts&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist09&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;host&gt;
  &lt;hostname&gt;cglist10&lt;/hostname&gt;
  &lt;/host&gt;
  &lt;/hosts&gt;
  &lt;/segment&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>Powershell Code :</p>
  
  <pre><code>[xml]$xd=gc "C:\Users\sxa8869\Desktop\Webserv\segmentcat.xml"
  $nodelist = $xd.selectnodes("/catalog/segment")
  
  $MasterArray = @()
  $MasterArray = "" | Select segmentname,hosts
  
  $file="C:\Users\sxa8869\Desktop\Webserv\sha.csv"
  
  foreach ($node in $nodelist) {
  
    $hostsNode = $node.selectSingleNode("hosts")
    $segmentname = $node.selectSingleNode("segmentname")
    $MasterArray.segmentname=$segmentname.get_InnerXml()
    foreach ($hostitem in $hostsNode) {
      $hostnamenodes = $hostitem.selectnodes("host")
      foreach ($hostname in $hostnamenodes) {
        $MasterArray.hosts=$hostname.selectSingleNode("hostname").get_InnerXml()
  
  #- Displays the hash in table format, want this format in csv
           $MasterArray        
  
  # - displaying only the last element
        $MasterArray | export-csv "file.csv" -notype      
  
  # - this works, but i want to use export-csv to get it in this format
   '"'+$MasterArray.segmentname+'"'+","+'"'+$MasterArray.hosts+'"'    
  
      }     
    } 
  } 
  
  
  Required output :-
   -----------------
  "segmentname","hosts"
  "Batch","cglist17"
  "Batch","cglist18"
  "Batch","cglist19"
  "Batch","cglist20"
  "Custom S2","cglist21"
  "Custom S2","cglist22"
  "eCommerce","cglist09"
  eCommerce,"cglist10"
  </code></pre>