$SharedDriveFolderPath = "\\---\shares\Groups\---\---\---\---\--\B\" $files = Get-ChildItem $SharedDriveFolderPath -Filter *.csv foreach ($f in $files){ $outfilename = $f.BaseName +'.xlsx' $outfilename #Define locations and delimiter $csv = "\\---\shares\Groups\---\---\---\---\--\B\$f" #Location of the source file $xlsx = "\\---\shares\Groups\---\---\---\---\---\---\C\$outfilename" #Desired location of output $delimiter = "," #Specify the delimiter used in the file # Create a new Excel workbook with one empty sheet $excel = New-Object -ComObject excel.application $workbook = $excel.Workbooks.Add(1) $worksheet = $workbook.worksheets.Item(1) # Build the QueryTables.Add command and reformat the data $TxtConnector = ("TEXT;" + $csv) $Connector = $worksheet.QueryTables.add($TxtConnector,$worksheet.Range("A1")) $query = $worksheet.QueryTables.item($Connector.name) $query.TextFileOtherDelimiter = $delimiter $query.TextFileParseType = 1 $query.TextFileColumnDataTypes = ,1 * $worksheet.Cells.Columns.Count $query.AdjustColumnWidth = 1 # Execute & delete the import query $query.Refresh() $query.Delete() # Save & close the Workbook as XLSX. $Workbook.SaveAs($xlsx,51) $excel.Quit() }