Save Excel directly as a CSV, fast:
$FilePath _public_ip_maps_infos="D:\My documents\work\ip Mapping table. xlsx"$Excel= New-object-Com Excel.Application$Excel. Visible =$False $Excel. displayalerts=$False $WorkBook=$Excel. Workbooks.Open ($FilePath _public_ip_maps_infos) #Save As CSV format, you need to set the parameter value to 6$Workbook. SaveAs ("D:\My documents\work\public_ip_maps_infos22.csv", 6) $Excel. Quit ()
It is inefficient to read Excel row by line and then save it as CSV:
#Read Load Balancer information table$strpath="D:\My documents\work\ip Mapping table. xlsx"$excel=new-object-ComObject Excel.Application$WorkBook=$excel. Workbooks.Open ($strpath)$WorkSheet=$WorkBook. Worksheets.item (1)#number of rows used$usedrows=$worksheet. Usedrange.rows.count$Public _ip_maps_info=$Public _ip_maps_infos=$null$Public _ip_maps_infos= @() for($i= 2;$i -le $usedrows;$i++){ $Public _ip_maps_info=""|Select PUBLIC_IP,INTERNAL_IP,IS_VIP$Public _ip_maps_info. public_ip =$WorkSheet. Cells.item ($i, 2). value2$Public _ip_maps_info. internal_ip =$WorkSheet. Cells.item ($i, 3). value2$Public _ip_maps_info. IS_VIP =$WorkSheet. Cells.item ($i, 4). value2$Public _ip_maps_infos+=$Public _ip_maps_info}$Public _ip_maps_infos$excel. Quit ()$WorkSheet=$null$WorkBook=$null$excel=$null[GC]:: Collect ()
To save CSV as Excel, refer to:
Http://www.pstips.net/converting-csv-to-excel-file.html
Save Excel as a CSV format file