Paul Hacker .Net, TFS, Etc…

November 5, 2010

List all TFS Project Collections and Projects

Filed under: Team System — phacker @ 1:39 pm

I recently had a request to list all project collections and the projects that are in the collections Here is what I came up with to do the trick. Maybe it will help someone else. I used the following website to help me out

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using System.Collections.ObjectModel;
using System.Net;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace TFS2010ProjectList
class Program
// without collection name
public static string url = @”http://tfsserverurl:8080/tfs”;

static void Main(string[] args)

private static void GetProjects()
TfsConfigurationServer srv = GetTfsConfigurationServer();
if (EnsureAuthentication(srv))
CatalogNode configurationServerNode = srv.CatalogNode;
// Query the children of the configuration server node for all of the team project collection nodes
ReadOnlyCollection tpcNodes = configurationServerNode.QueryChildren(
new Guid[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);

foreach (CatalogNode tpcNode in tpcNodes)
Guid tpcId = new Guid(tpcNode.Resource.Properties[“InstanceId”]);
TfsTeamProjectCollection tpc = srv.GetTeamProjectCollection(tpcId);
//Console.WriteLine(“{0}”, tpc.Name);

var workItemStore = tpc.GetService();

// go over the next node if no projects available
if (workItemStore.Projects.Count <= 0)
// iterate over the projects
foreach (Project project in workItemStore.Projects)
Console.WriteLine("\tProject: {0}", project.Name);



public static TfsConfigurationServer GetTfsConfigurationServer()
return new TfsConfigurationServer(new Uri(url), GetCredentials(), new UICredentialsProvider());
} [System.Diagnostics.DebuggerStepThrough]

private static ICredentials GetCredentials()
return new NetworkCredential("username", "password", "Domain");
public static bool EnsureAuthentication(TfsConfigurationServer srv)
bool result = true; try
result = srv.HasAuthenticated;
catch (Exception)
result = false;

return result;

1 Comment »

  1. […] List all TFS Project Collections and Projects […]

    Pingback by Links – 11/09/2010 « Team System Rocks! — November 9, 2010 @ 2:09 pm

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The WordPress Classic Theme. Create a free website or blog at


Get every new post delivered to your Inbox.

%d bloggers like this: