1

Can somebody tell me how to read a csv file with numeric headers in powershell Eg:

 1,2,3,4,5,6 
 value1,value2,value3,value4,value5,value6
 value1,value2,value3,value4,value5,value6
 value1,value2,value3,value4,value5,value6

I tried following

$csvObject = Import-Csv -Path <file name>
ForEach ($dataRow in $csvObject) {
  $val1 = $dataRow.1
  Write-Host $val1
}

and it didn't work, can someone guide me how should I read this file?

4
  • 1
    Error message? Symptoms of failure? Commented Nov 28, 2014 at 2:27
  • I've just tried it and it works as expected on PowerShell 4; Which version of PowerShell are you using? Commented Nov 28, 2014 at 2:35
  • Thanks @andyb and @TessellatingHeckler. Actually bit newbie to powershell, I could done it with the way I did it, only issue occurred when I tries to get the value in upper case. Eg: $dataRow.1 .ToUpper(). Powershell ISE showed that as an error. To fix it, I changed it as $dataRow."1".ToUpper(). Everything works as expected now. Thanks for your time again. Oh what am I gonna do with this question now Commented Nov 28, 2014 at 2:45
  • I almost suggested quoting the 1 until I tried it and found it didn't need it to do a basic lookup. Good that you solved it - I suggest you post what you did as an answer and accept your own answer; that's an acceptable thing to do on Stackexchange. Commented Nov 28, 2014 at 2:50

1 Answer 1

1

I figured it out, issue was when I tried to use value as upper case, powershell ISE showed me it as syntax error. so I changed it to $dataRow."1".ToUpper() instead $dataRow.1.ToUpper().

Thanks.

Sign up to request clarification or add additional context in comments.

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.