8

I am trying to "Get Latest Version" of a particular folder from TFS, using Powershell.

I have installed the TFS Snappin, and have been using TFS Power Tools cmdlets in PowerShell (such as Get-TfsChildItem and Select-TfsItem etc) [How do I set up TFS PowerShell Snapin ], and have gone through their documentation (which I didn't find explanatory enough!).

Confused, on the exact cmdlet to use, when I am trying to get the latest version of an entire Folder structure from TFS, that is mapped to my local drive (and not just a changeset or ChildItem).

Example : Tfs Path - $/APD-RepairSolutions/Main/Database

Mapped path - D:\TFS\APD-RepairSolutions/Main/Database.

I want a code, that would iteratively get the latest version of the entire folder Database,( that has number of tables,stored procedures etc.)

I am using ..

PS D:\Tfs\APD-RepairSolutions\Main\Database> $server=Get-TfsServer -Name http://tfs:8080/tfs

PS D:\Tfs\APD-RepairSolutions\Main\Database> Get-TfsChangeset -Recurse -Server $Server

Not helping my case - as it is only returning the latest changeset in the current directory.

Community
  • 1
  • 1
ArNumb
  • 307
  • 1
  • 4
  • 10

3 Answers3

8

To get latest (tf get) use Update-TfsWorkspace.

Get-TfsChangeset is the equivalent of tf changeset.

KMoraz
  • 14,004
  • 3
  • 49
  • 82
2

Gotcha! with Update-TFSWorskpace. Has some helpful parameters as well. -Items is used to specify the exact items you want to update.

PS D:\Tfs\APD-RepairSolutions\Main>Update-TFSWorkspace -All -Overwrite -Force -Recurse -Items .\Database

The Workspace is replaced with updated versions of items. Thanks @Kmoraz!

ArNumb
  • 307
  • 1
  • 4
  • 10
2

If you would like to use the TFS API instead, you can use the Workspace.Get Method:

# Load the TFS assemblies
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
$ws = $vcServer.QueryWorkspaces("<WORKSPACENAME>", $null, $null);

# Specify properties of intended workspace get
$recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
$latestVersion = [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::Latest
$getOptions = [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::GetAll

# Get what I want!
$ws.Get("$/Remote/Folder", $latestVersion, $recursionType, $getOptions)

Would be a good idea to replace the nulls with your domain login and computer name when Querying Workspaces.

Mike Sanders
  • 49
  • 1
  • 8
  • 1
    This is great! For reference, changing GetOptions to Overwrite seems to match "Get Latest Version" in Visual Studio: ....`.GetOptions]::Overwrite` – AndrewRalon May 23 '17 at 15:11