
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.