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

closed as off-topic by Robert Lindgren Jun 18 '14 at 17:23

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions not specific to SharePoint are off-topic here, but can be asked on Stack Overflow." – Robert Lindgren
If this question can be reworded to fit the rules in the help center, please edit the question.

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
  • 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.