title: Using Sort-Object on array of hash tables
body: <p>After creating the following array of hash tables in PowerShell (version 2):</p>
  
  <pre><code>$array = @()
  $array += @{a = 1; b = 5}
  $array += @{a = 3; b = 4}
  $array += @{a = 5; b = 9}
  $array += @{a = 7; b = 2}
  </code></pre>
  
  <p>All the following calls to Sort-Object return the same {a,b} sequence: {5,9},{7,2},{1,5},{3,4}:</p>
  
  <pre><code>$array | Sort-Object
  $array | Sort-Object -Descending
  $array | Sort-Object a
  $array | Sort-Object b
  $array | Sort-Object "a"
  $array | Sort-Object -Property a
  $array.GetEnumerator() | Sort-Object
  $array.GetEnumerator() | Sort-Object a
  </code></pre>
  
  <p>If <code>$array</code> is called directly, it returns the objects in the order that they were entered, so the sort is changing the order. But perhaps it has no comparer so just treats every object as equal??</p>
  
  <p>The goal is to sort all of the objects. I am fine with workarounds that involve an alternate custom object, an alternate collection and/or an alternate sort routine.</p>
  
  <p>Edit: To clarify what I'm trying to achieve, this would be a rough equivalent in C#</p>
  
  <pre><code>class MyClass {
      public int a;
      public int b;
  }
  
  // somewhere inside a method:
  var objects = new List&lt;MyClass&gt;();
  // code here to populate objects with some MyClass instances.
  var sorted = objects.OrderBy(x =&gt; x.a);
  </code></pre>