Use Powershell to execute a TFS console app for each team project

by Ewald Hofman 7. September 2009 23:18

I wanted to remove one of the field mappings for MS Project for all team projects. Of course I could create a simple batch file and then retrieve all team project names from somewhere and copy the command several times. But as a real IT guy: I am lazy.

So I wanted to automate the process. Of course I could have used the TFS API, but then you have to start visual studio, put in the same code over and over again. I wanted to explore new fields, being Powershell.

There is a lot of information about powershell on the web. An excellent blog is from James Manning. But you can also see the Powershell help on Technet.

This post covers the execution of the TFSFieldMapping.exe on all team projects to upload new field mappings.

Step  Descriptio 
To be able to iteraterate through the team projects, we need to make a connection to TFS. There is an excellent script, created by James Manning, called get-tfs, which you can find at:  
2 Download the script and place it in the same directory as your script will be saved.
3 Create a new file called UploadMappings.ps1
4 Open the file in notepad
5 Enter the contents (see below) in the file
6 Save the file
7 Open the command prompt
8 Type Powershell
9 Go with cmd "my dir" to the directory where your script is located
10 Type .\UploadMappings

The full script looks like



 $cmd = """c:\program files\Microsoft Visual Studio 9.0\Common7\IDE\tfsfieldmapping.exe""";
 $server = "[TFS URL (eg. http://mytfsserver:8080)]";
 $tfs = .\get-tfs $server;
 $css = $tfs.css;
 $mappingfile = "[location of mapping file]";

 $css.ListAllProjects() | % {
  "Upload fields for $_";
  $info = new-object System.Diagnostics.ProcessStartInfo;
  $info.FileName = $cmd;
  $info.Arguments = "upload $server ""$_"" $mappingfile";
  $info.UseShellExecute = $false;
  $p = [diagnostics.process]::start($info);


VSTS 2008

Comments are closed

Powered by BlogEngine.NET
Theme by Mads Kristensen


Widget Statistics not found.

There is an error in XML document (0, 0).X

Recent comments

Comment RSS