While building out an automation process I needed to convert a xlsx file to a csv file for further parsing within powershell. Unfortunately this is not built into powershell, and excel needs to be installed on the system for this to work. Although its not a powershell cmdlet the solution is quite simple:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Function ExcelCSV ($File) { $excelFile = "$pwd\" + $File + ".xlsx" $Excel = New-Object -ComObject Excel.Application $Excel.Visible = $false $Excel.DisplayAlerts = $false $wb = $Excel.Workbooks.Open($excelFile) foreach ($ws in $wb.Worksheets) { $ws.SaveAs("$pwd\" + $File + ".csv", 6) } $Excel.Quit() } $FileName = "Book1" ExcelCSV -File "$FileName" |
For the file location I leverage $pwd, this can be altered to what ever is needed but for a test script this is most likely the easiest way to get it running to test. The script will make a csv file from the xlsx specified using the exact same file name.