title: Using PowerShell to import data properly into an array
body: <p>I am trying to put together a PowerShell script that will read data from a CSV (it is actually tab separated and not CSV but for SO, we'll use commas) and import that data into a PowerShell multidimensional array.  My CSV has the following data:</p>
  
  <pre><code>EmpID,Name,Dept
  12345,John,Service
  56789,Sarah,Sales
  98765,Chris,Director
  </code></pre>
  
  <p>My script is as follows:</p>
  
  <pre><code>$temp=gc "temp.csv"
  $array=@()
  
  $temp | Foreach{
      $elements=$_.split(",")
      $array+= ,@($elements[0],$elements[1],$elements[2])
  }
  
  foreach($value in $array)
  {
      write-host "EmpID =" $value[0] "and Name =" $value[1] "and Dept =" $value[2]
  }
  </code></pre>
  
  <p>The above works, but I would like is to be able to refer to the array elements by a more proper name because there are a lot more elements than are shown above and this gets confusing.  To do this, I’ve tried to use hash tables, defining new objects, members, types, etc. but they never seem to work properly.  I may be wrong but I feel like I’m running in a circle and now I may be lost.  Basically, what I want to do is, instead of using:</p>
  
  <pre><code>write-host "EmpID =" $value[0] "and Name =" $value[1] "and Dept =" $value[2]
  </code></pre>
  
  <p>I would like to replace the above with something like this:</p>
  
  <pre><code>write-host "EmpID =" $value.EmpID "and Name =" $value.Name "and Dept =" $value.Dept
  </code></pre>
  
  <p>Is this possible?  If so, can someone point me in the correct direction?  The CSV is coming from another source and comes with the header row anyway (it can’t be removed except by manually editing the CSV).  So I would like to use the header row to name the array columns but I don’t have to use it.  My primary question (goal) here is to at least be able to name the different columns.  It can be done either dynamically by using the first row imported from the CSV or by entering the names into the script itself.</p>
  
  <p>Thanks</p>