count array, create enough variables for number of array items as variables then knowingly call them

am trying to create a function for tables. i figured the best way would be to put my column headers in an array, count the array, set a variable as 0 to use as a counter, and while the array count is greater than the counter, set a variable called "col1" or whatever the counter is. i can then setup datatable structures for the columns.
problem is, how do i then call them??
Who is Participating?
Well, I suppose you could do it like this.

$arrHeaders = "col1","col2","col3","col4"
foreach ($variable in $arrHeaders)
   New-Variable -Name $variable
   Get-Variable $variable

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.