blog community

Welcome to blog community Sign in | Join | Help
in Search

Willem Meints

Deleting browser cookies ... Best done with a glass of milk

Getting latest files from TFS using PowerShell

Since not all our files that are in TFS source control are used from Visual Studio it’s kind of overdone to start visual studio for getting the latest version of a SQL script. However, working with tf.exe is somewhat cumbersome too. The shear amount of commandline parameters got me wondering why I didn’t have a powershell script to make the task of getting the latest version of a file a little easier.

The following powershell script can be dot-sourced (Will talk about that in a minute) so you can just invoke Get-LatestVersion from the powershell console to get the latest version of all files in a particular folder and subfolders.

function Get-LatestVersion() {
    $location = get-location
    tf.exe get $location / version:T / recursive / force
}

To use this function from powershell, you can save the fragment to a ps1 file and invoke the script using the following commandline:

. TFSExtensions.ps1

Note the dot in front of the script, this means that powershell dot-sources the function. By dot-sourcing the script gets imported in the runspace of powershell so that it is available during the time you have that powershell session open.

For even easier access I added the dot-source command to my profile script, so the extensions get loaded each time I run powershell.

Published Thursday, August 07, 2008 10:04 AM by willemm

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server, by Telligent Systems