0

I have a table in a variable in a specific format (similar to csv)

| ID  | Status | Notes  |
| 1   | OK     | A      |
| 2   | OK     | B      |

any suggestions on how to convert it into an array of objects? I've tried select-object but doesn't really do it.

Thanks

Andrew White
  • 1,770
  • 4
  • 25
  • 43
  • where is the table? Is it in a PS variable? If so, what type? Is it in a file? If so, is it just a csv that uses pipe as a delimiter? If so, Import-csv is your answer, using the delimiter parameter as shown in the previous comment. – Walter Mitty Nov 17 '15 at 11:19

1 Answers1

0

Try this:

$objects = Import-csv "myfile.dat" -delimiter "|"

The variable will contain an array of Custom objects.

Walter Mitty
  • 18,205
  • 2
  • 28
  • 58
  • Will it matter that it's not true delimited text as all lines start and finish with the delimiter? – Andrew White Nov 17 '15 at 13:05
  • Yes, it will probably matter. I don't know what import-csv will do with that. Maybe each record will have NULL in the first and last position, but that leaves unanswered what it will do on the header record. Try it and see what you get. – Walter Mitty Nov 17 '15 at 15:11