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: http://blogs.msdn.com/jmanning/archive/2006/09/28/776141.aspx  
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

 

param(

)
begin
{
 $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]";
}

process
{
 $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);
  $p.WaitForExit();
 }
}

Tags:

VSTS 2008

Comments are closed

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen


ClusterMap

Widget Statistics not found.

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

Recent comments

Comment RSS