I have non-working code similar to the following:
$list = Get-VM | format-table VMElementName -HideTableHeaders | out-string
$array=@($list)
Write-Host $array[1]
What I end up is $array[0] filled with a list of data and no values in $array[1] or higher.
String1
String2
String3
What is the best way to parse this list to populate the array?
format-table, you should useselect-object. That way you are still working with objects rather than strings. If you don't want the header, you can use the-ExpandPropertyparameter.Format-Table(or any otherFormat-cmdlet) unless you never want to use that data as data again. As soon as you format it, it's no longer usable. Also, you shouldn't useWrite-Hostin 90% of situations.