title: powershell sorting really large collection of objects
body: <p>I am trying to generate histograms from a very large collection of objects (-gt 250k).  I need to sort the collection on a property of each object.  My line of script looks like:</p>
  
  <pre><code>$ch = $ch | sort TotalCount -descending  &lt;br&gt;
  </code></pre>
  
  <p>where <code>$ch[x].totalcount</code> would be some integer.  </p>
  
  <p>The script works but it takes over an hour to sort and consumes 6GB of memory.  How do I speed up the process?</p>
  
  <p>I've done some searching for a solution and several web sites suggest using [array]::sort as it is much quicker.  As this is a collection of objects, I'm not sure how I would use a static <code>System.Array</code> sort method.  Even if I could, I don't see how to make the array descending (although reversing the result should be pretty simple).</p>
  
  <p>Any suggestions on how to sort really large collections with powershell?</p>