I am new to powershell, don't get to use this often.
I need to output the value of cell A5 from a csv file using powershell
my file -
col1 col2 col3 col4
---- ---- ---- ----
1002 1005 1006 1007
need value in the A1 cell i.e 1002.selection should be done by the cell numbers.
$a = @(Import-CSV filepath.csv)
$a[1].(col1)
thanks in advance
Import the CSV to your variable
$a = Import-CSV filepath.csv
Then grab the first row $a[0]
and use .
notation to get the column you want. Note that the first row of data is 0
because powershell converts the CSV to an object, seperating the headers and data.
$a[0].col1
If you don't need any other values from the CSV, then you can forego the variable assignment and trim it down to:
(Import-CSV filepath.csv)[0].col1
Row 1, Column 1 (A1)
$a[0].psobject.properties.value[0]
Row 1, Column 5 (A5)
$a[0].psobject.properties.value[4]