title: Powershell - hash table from an array
body: <p>I have an array in Powershell with the following rows:
  1,Tgt,10,Fld
  2,XM,8,Fi
  3,TX,12,Fi</p>
  
  <p>First column is the row counter, second column is a filter type, 3rd column is a count, 4th column is an Action Type.</p>
  
  <p>I need to create a hash table of the 2nd &amp; 3rd columns.  </p>
  
  <p>When I do the following in Powershell, it creates a hash table I can use.  </p>
  
  <pre><code>$z=@()
  $z = {
  Tgt = 10
  XM = 8
  TX = 12
  }
  </code></pre>
  
  <p>But, if I use a foreach to attempt to do the same thing, it creates a collection of the collection.  </p>
  
  <pre><code>foreach ($b in $arr) {
     $z2 += @{$b[1] = $b[2]}
     }
  </code></pre>
  
  <p>Each has 3 elements in it, but the hash table $z is a <code>{System.Collections.DictionaryEntry,System.Collections.DictionaryEntry,System.Collections.DictionaryEntry}</code></p>
  
  <p>while hash table $z2 is a </p>
  
  <pre><code>{{System.Collections.DictionaryEntry},{System.Collections.DictionaryEntry},{System.Collections.DictionaryEntry}}
  </code></pre>
  
  <p>$z can be referenced in a foreach by using the $z.Keys, but I can't reference the same thing on $z2. Even though each has 3 rows, $z is an array of 3 rows, but $z2 is an array of 3 arrays of 1 row each. What I want to do is to have $z and $z2 hash table be identical to each other in every way.  </p>
  
  <p>I'm sure I am doing something obvious &amp; wrong trying to create this hash table from the existing array, but cannot figure out what I'm doing wrong.   Any suggestions appreciated.</p>
  
  <p>Thanks!</p>