Tuesday, January 8, 2013

PowerShell CmdLet to Get the Latest TFS Changeset Number

Sometimes, as a part of a scripted activity (e.g. packaging) you need to determine the latest TFS Changeset number / revision of your working copy. The following handy PowerShell script does just this, and it was just nuanced enough to figure out how to do it that I thought I'd share it here. For the really interested, the two nuances are:

You have to use the history command with the recurse option. If you use history without recurse, or if you use the info command, it only interrogates a specific folder or file's data, and not the checkout, meaning you won't get the latest revision for the entire working copy.

You have to use the /noprompt option to cause the history to be outputted to the console window instead of viewing the information in a dialog box. The option is not appropriately described and command line tools shouldn't open dialog boxes, but that is the situation here.