title: Powershell Sort-Object by [DateTime]::ParseExact
body: <p>I'm trying to sort the lines returned by a console program by date, using PowerShell.</p>
  
  <p>The dates are formated in MM/dd/yyyy format, so they have to be converted to DateTime objects to be in a sortable format.</p>
  
  <p>To parse the dates, I use:</p>
  
  <pre><code>$dates = %{ "10/24/2010", "02/03/2010" }
  $dates | %{ [System.DateTime]::ParseExact($_, "MM/dd/yyyy", $null) }
  </code></pre>
  
  <p>This parses the dates into System.DateTime objects and displays their default ToString() representation, but it also shows an additional blank line at the beginning.</p>
  
  <p>Now, if I try to sort the dates with Sort-Object, I get an error message, and I guess the error comes from the additional blank line:</p>
  
  <pre><code>$sortedDates = $dates | Sort-Object [System.DateTime]::ParseExact($_, "MM/dd/yyyy", $null)
  </code></pre>
  
  <p>Error message: </p>
  
  <blockquote>
    <p>"Sort-Object : A positional parameter cannot be found that accepts argument 'System.Object[]'."</p>
  </blockquote>
  
  <p>Where is the extra blank line coming from? Am I doing something wrong to parse the dates, or to sort them?</p>