2

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

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

Comments

2

Row 1, Column 1 (A1)

$a[0].psobject.properties.value[0]

Row 1, Column 5 (A5)

$a[0].psobject.properties.value[4]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.