title: Convert Object to Associative Array in PowerShell
body: <p>Background: I'm getting data in JSON format and have to use it with <code>Set-QADUser</code> (from the Quest ActiveRoles Management Shell) to update a user in Active Directory.</p>
  
  <p>Just providing the data parsed from JSON to the cmdlet results in this error message:</p>
  
  <blockquote>
    <p>Unable to index into an object of type System.Collections.Generic.Dictionary`2+ValueCollection[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].</p>
  </blockquote>
  
  <p>I can iterate over the object like this:</p>
  
  <pre><code>PS C:\scripts&gt; $data.params | ForEach-Object { $_ }
  
  Key               Value
  ---               -----
  manager           CN=smith,OU=Employees,OU=People,OU=Department,OU=...
  department        Department
  company           Company
  homeDirectory     \\\\win7x64gerald.testdomain.com\\jdoe
  homeDrive         U:
  primaryGroupID    1501
  userPrincipalName jdoe@testdomain.com
  </code></pre>
  
  <p>But Set-QADUser expects the data to be in an associative array format (or Hashtable). Example from the Help:</p>
  
  <pre><code>C:\PS&gt;Set-QADUser 'mycompany.com/usersOU/User1' -objectAttributes @{otherTelephone=@('555-34-67','555-34-68')}
  </code></pre>
  
  <p>I would expect to be able just loop over it as above and access the Key and Value parameter like this:</p>
  
  <pre><code>PS C:\scripts&gt; $data.params | ForEach-Object { $_.Key }
  </code></pre>
  
  <p>But this just shows nothing.</p>
  
  <p><code>$data.params.keys</code> shows all keys, same with values, but I can't fetch a specific one by just appending <code>[0]</code>, and there is no get-method I can find.</p>
  
  <p>So, how can I convert an object like this into an associative array?</p>