title: Parsing XML & Output to Excel
body: <p>I'm making a script that will parse through 2,000 XML files for data &amp; then output it to an Excel file.
  Here's what I have so far:</p>
  
  <pre><code>#Get XML File
  $path = Get-ChildItem C:\Users\bcamareno\Desktop\xml\xml
  
  #Start Excel
  $xl=New-Object -ComObject "Excel.Application"
  $wb=$xl.Workbooks.Add()
  $ws=$wb.ActiveSheet
  
  $cells=$ws.Cells
  $cells.item(1,1)="HDD Report"
  $cells.item(1,1).font.bold=$True
  $cells.item(1,1).font.size=18
  
  #Rows &amp; Cols
  $row=3
  $col=1
  $A=4
  $B=4
  $C=4
  $D=1
  $E=2
  $F=3
  
  #column headings
  "Server","Disk0","Disk1","Disk2","Disk3","Disk4","Disk5","Disk6","Disk7" | foreach {
      $cells.item($row,$col)=$_
      $cells.item($row,$col).font.bold=$True
      $col++
  }
  
  #Site Code
  foreach ($item in $Path) {
  $cells.item($A,$D)= $item -replace "_pdisk.xml",""
        $A++
  }
  
  #Grab ProductID
  foreach ($item in $Path) {
      [xml]$content = Get-Content "c:\Users\bcamareno\Desktop\xml\xml\$item"
      $try= $Content.SelectNodes('//ProductID') | select "#Text"
      $cells.item($B,$E)= $try -replace "@{#text=","" -replace "}",""
      $B,$E++
  }
  
  $xl.Visible=$True
  </code></pre>
  
  <p>But when I run it, the data comes out wrong, it seems like it's only parsing the last file &amp; then adding that result to the cells.</p>
  
  <p>I can add an XML if needed.</p>