title: How do I download all versions of a file in TFS with PowerShell?
body: <p>I have Visual studio PowerTools installed and am trying to download the physical files that are associated with every changeset.</p>
  
  <p>I can find all changesets associated with a file and downloaded the latest version of the file by performing the following:</p>
  
  <pre><code>$tfsServer = Get-TFSServer 'http://myserver/tfs'
  $history = Get-TfsItemHistory -HistoryItem $tfsHistoryItem -Server $tfsServer
  $tfsProjColl = Get-TfsProjectCollection -Uri $tfsRootUrl
  $tfsVersionControl = $tfsProjColl.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])
  foreach ($h in $history)
  {
      $tempFilePath = [System.IO.Path]::GetTempFileName()
      $item = Get-TfsItemProperty -Item $h -Server $tfsServer
      $tfsVersionControl.DownloadFile($item.SourceServerItem, $tempFilePath)
  }
  </code></pre>
  
  <p>At first, I thought I had it but <code>SourceServerItem</code> simply is a reference to the same file which is the latest. How can I download the version of the file that was checked at that time?</p>