title: Converting Multiple CSV's to a single Xlsx
body: <p>I have a script that creates x amount of csv's I want to convert all the csv's in the folder into one Xlsx file.</p>
  
  <p>I have the basics of cycling through each csv, however it overwirtes after the end of each loop.</p>
  
  <p>I have want to add each csv to a worksheet in the workbook and save it.</p>
  
  <p>but it only displays the last csv it read and doesn't show any other worksheets.</p>
  
  <p>I have sampled the code from the following;</p>
  
  <p><a href="https://stackoverflow.com/questions/17688468/how-to-export-a-csv-to-excel-using-powershell">How to export a CSV to Excel using Powershell</a></p>
  
  <p>As discussed, I have tried the above; no luck.</p>
  
  <pre><code>Function Excel-Write{
  $RD = "C:\temp\Servers\*.csv"
  $CsvDir = $RD
  
  $csvs = dir -path $CsvDir
  $outputxls = ""C:\temp\Servers\Complete.Xlsx"
  
  foreach($iCsv in $csvs){
    $WB = $csvs.Length
      $Excel = New-Object -ComObject excel.application
      #$Excel.displayAlerts = $false
      $workbook = $excel.Workbooks.add(1)
      $Worksheet = $workbook.worksheets.Item(1)
      $Worksheet.name = $Group
  
      $TxtConnector = ("TEXT;" + $iCsv)
      $Connector = $worksheet.Querytables.add($txtconnector,$worksheet.Range("A1"))
      $query = $Worksheet.QueryTables.item($Connector.name)
  
      $query.TextfileOtherDelimiter = $Excel.Application.International(5)
  
      $Query.TextfileParseType =1
      $Query.TextFileColumnDataTypes = ,2 * $worksheet.cells.column.count
      $query.AdjustColumnWidth =1
  
      $Query.Refresh()
      $Query.Delete()
  
          $workbook.Save()
  
  }
  $Workbook.SaveAs($outputxls,51)
  $Excel.quit()
  } 
  </code></pre>
  
  <p>Only shows one worksheet and this is the last CSV that has been read, it overwrites other worksheets.</p>