1

I have a file with data in how can I put this into an array in powershell The file look a bit like this :

  name
-------------------

 this
 pickle
 is
 yes
 Jimmy
 Pimms

Would be good if I could ignore the title and just get what's under it

2

You can use either this which just create an array of object

$a = Get-Content .\test.txt | Select-Object -Skip 3

or this which will change the type to array of string

$a = [string[]](Get-Content .\test.txt | Select-Object -Skip 3)

or this which creates an array of PSCustomObjects with a name property

$a = Import-Csv .\test.txt | select-Object -skip 1
| improve this answer | |
  • what if I want them to be strings? – bimbob Jun 18 '14 at 12:10
  • The elements of the first array is strings and the name property of the last is strings, but as shown in the second you can force the first to be an array of strings – Per Jakobsen Jun 18 '14 at 12:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.