1

I have a csv file with large number of columns . I have imported it to a table using the below code:

$table = Import-Csv "C:\data.csv"
$row = $table.Item(0);
$row.'Title'

I want to access the column using number . I want to do something like this :

$row[0]

How do I achieve this ?

2 Answers 2

2

Something like this, maybe?

$table = import-csv "C:\data.csv"
$cols = $table[0].psobject.properties.name

$table.$($cols[0])
Sign up to request clarification or add additional context in comments.

1 Comment

This Worked . Thanks a lot . I modified it like this : $cols = $table[0].psobject.properties.name $colName = $cols[0]; $colName $table[0].$colName
0

This should work for CSV:

$table[0]
$table[0].Title

I want to access the column using number . I want to use a for loop.

This is for rows, for the columns, see mjolinor's answer.

$table = Import-Csv Import-Csv 'C:\data.csv'

for($i=0; $i -lt $table.Count ; $i++){
    $table[$i].Title
}

1 Comment

I want to access the column using number . I want to use a for loop . This wont work.

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.