title: Useful PowerShell one liners
body: <p>Provide one line PowerShell script that you found useful, one script per answer please. </p>
  
  <p>There is a similar <a href="https://stackoverflow.com/questions/285064/what-are-some-good-powershell-script-repositories">question here</a>, but this one gives only links to pages with scripts, lets answers one by one here and have a contributed list of most frequently used or most useful scripts.</p>
  
  <ol>
  <li><p>List most recent version of files</p>
  
  <p><code>ls -r -fi *.lis | sort @{expression={$_.Name}}, @{expression={$_.LastWriteTime};Descending=$true} | select Directory, Name, lastwritetime | Group-Object Name | %{$_.Group | Select -first 1}</code></p></li>
  <li><p><code>gps programThatIsAnnoyingMe | kill</code></p></li>
  <li><p>Open a file with its registered program (like <code>start</code> e.g <code>start foo.xls</code>)</p>
  
  <p><code>ii foo.xls</code></p></li>
  <li><p>Retrieves and displays the paths to the system's Special Folder's</p>
  
  <p><code>[enum]::getvalues([system.environment+specialfolder]) | foreach {"$_ maps to " + [system.Environment]::GetFolderPath($_)}</code></p></li>
  <li><p>Copy Environment value to clipboard (so now u know how to use clipboard!)</p>
  
  <p><code>$env:appdata | % { [windows.forms.clipboard]::SetText($input) }</code>
  <br/>OR<br/>
  <code>ls | clip</code></p></li>
  </ol>
  
  <p><strong>With SnapIns</strong></p>
  
  <ol>
  <li><p>Files between two changeset numbers in TFS</p>
  
  <p><code>Get-TfsItemHistory &lt;location&gt; -Recurse -Version &lt;label1&gt;~&lt;label2&gt; | 
  % { $(Get-TfsChangeset $_.ChangeSetID).Changes } |
  % { $_.Item.ServerItem } | Sort-Object -Unique</code></p></li>
  <li><p>Gets queue messages with errors over all Hub servers in exchange 200</p>
  
  <p><code>Get-ExchangeServer | ?{$_.IsHubTransportServer -eq $true} | Get-Queue 
  | ?{$_.LastError -ne $null} | Sort-Object -Descending -Property MessageCount 
  | ft -Property NextHopDomain,@{l="Count";e={$_.MessageCount}},@{l="Last Try";e={$_.LastRetryTime.tosting("M/dd hh:mm")}},@{l="Retry";e={$_.NextRetryTime.tostring("M/dd hh:mm")}},Status,LastError -AutoSize</code></p></li>
  </ol>