Say I have an Excel file:
I need to create n variables called $col1 up to $coln and read in their respective values.
What is the best approch? I have been trying with a hashtable but I need to be able loop through the columns. This is my code. I have not wraped it around a loop yet. I can create the column names manually but I need to be able to index the columns in the Excel file.
$ExcelRowToRead = 2;
$ListOfColumns = @{"Job_name" = 1 ; "Run_time_start" = 2}
$excel = New-Object -ComObject excel.application;
$workbook = $excel.Workbooks.Open("pathtofile.xlsx");
$workbook.sheets.item(1).activate()
$WorkbookTotal=$workbook.Worksheets.item(1)
$ListOfColumns["Job_name"] = $WorkbookTotal.Cells.Item($ExcelRowToRead, 1) # This needs to be an index
$ListOfColumns["Job_name"].Text

Import-CSVcmdlet. ///// if you can use a 3rd party module, take a look at the ImportExcel module. it's quite nifty ... [grin]