title: How do you check if a PowerShell variable is an ordered hashtable?
body: <p>In PowerShell, how do you check if a variable is a hashtable, whether it be ordered or not?</p>
  
  <p>In the first instance, I was testing if an ordered hashtable was of type <code>Hashtable</code>, but it seems that it is not.</p>
  
  <p>Following this, I checked the variable type using <code>GetType()</code>. This seems to show that ordered hashtables are of type <code>OrderedDictionary</code>.</p>
  
  <p>Finally, I tested if an ordered hashtable was of type <code>OrderedDictionary</code>, but this results in an error.</p>
  
  <p>I assume that there must be a way to do this?</p>
  
  <h3>Checking for <code>Hashtable</code> only</h3>
  
  <pre><code>$standard = @{}
  $ordered = [ordered]@{}
  
  if ($standard -is [Hashtable]) { Write-Output "True" } else { Write-Output "False" }
  if ($ordered -is [Hashtable]) { Write-Output "True" } else { Write-Output "False" }
  </code></pre>
  
  <blockquote>
    <p>True<br>
    False</p>
  </blockquote>
  
  <h3>Getting the type of variable for normal and ordered hashtables</h3>
  
  <p>Looking at the type of the variables, I can see that <code>$ordered</code> seems to be a different type called <code>OrderedDictionary</code>.</p>
  
  <pre><code>$standard = @{}
  $ordered = [ordered]@{}
  
  Write-Output $standard.GetType()
  Write-Output $ordered.GetType()
  
  
  
  IsPublic IsSerial Name              BaseType  
  -------- -------- ----              --------  
  True     True     Hashtable         System.Object  
  True     True     OrderedDictionary System.Object
  </code></pre>
  
  <h3>Checking for <code>Hashtable</code> or <code>OrderedDictionary</code></h3>
  
  <p>However, when I check if a variable is of type <code>OrderedDictionary</code>, I'm presented with an error stating that the type cannot be found.</p>
  
  <pre><code>$standard = @{}
  $ordered = [ordered]@{}
  
  if (($standard -is [Hashtable]) -or ($standard -is [OrderedDictionary])) { Write-Output "True" } else { Write-Output "False" }
  if (($ordered -is [Hashtable]) -or ($ordered -is [OrderedDictionary])) { Write-Output "True" } else { Write-Output "False" }
  </code></pre>
  
  <blockquote>
    <p>True<br>
    Unable to find type [OrderedDictionary].</p>
  </blockquote>