title: How to parse a csv file with powershell for specfic results
body: <p>I have a CSV file containing log on data for users and would like to use PowerShell to parse the data to find the last log on for each user.</p>
  
  <p>The data is in the format:</p>
  
  <pre><code>TimeStamp                  UserName                           
  ---------                  --------                           
  10/14/2011 12:53:12 PM     Smith                      
  10/14/2011 12:54:07 PM     Jones                      
  10/14/2011 12:59:45 PM     Green                      
  10/14/2011 1:10:43 PM      Brown                      
  8/20/2012 6:20:11 PM       Jones                     
  8/20/2012 6:20:36 PM       Brown                     
  8/20/2012 6:33:04 PM       Smith                      
  8/20/2012 6:35:45 PM       Brown                  
  8/20/2012 6:45:05 PM       Jones                  
  8/20/2012 6:45:45 PM       Smith 
  </code></pre>
  
  <p>The desired output is:</p>
  
  <pre><code>UserName                   TimeStamp                          
  --------                   ---------                           
  Brown                      8/20/2012 6:45:45 PM
  Green                      10/14/2011 12:59:45 PM
  Jones                      8/20/2012 6:45:05 PM
  Smith                      8/20/2012 6:45:45 PM
  </code></pre>
  
  <p>I could do this with a row by row, nested loop, solution but that seems a poor way to approach it with PowerShell.</p>
  
  <p>I can read in the csv data and sort it by UserName and TimeStamp thus:</p>
  
  <pre><code>$data = "\\SomePath\LastLogon.csv"
  $list = Import-Csv $data |Sort @{expression="UserName";Ascending=$true},@{expression="TimeStamp";Descending=$true}
  $list
  </code></pre>
  
  <p>But I'm now stuck on how to filter for just the last log on. Is there a simple way to do this with PowerShell or am I taking the wrong approach?</p>