Mariusz, Gorzoch tech Blog

How to enumerate all members from all groups in TFS project collection

leave a comment »

Even if above sound difficult then in reality this is quite simple. First what we need to do is to add references to:

  • Microsoft.TeamFundation
  • Microsoft.TeamFundation.Client
  • Microsoft.TeamFundation.Common

and next, use below peace of code :

TfsTeamProjectCollection teamProjectCollection =
TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(“http://TFS:8080/tfs/ProjectCollection”));

var sec = teamProjectCollection.GetService<IGroupSecurityService>();

var vcs = teamProjectCollection.GetService<VersionControlServer>();

var teamProjects = vcs.GetAllTeamProjects(false);
foreach (var teamProject in teamProjects)


Identity[] appGroups = sec.ListApplicationGroups(teamProject.ArtifactUri.AbsoluteUri);

foreach (Identity appGroup in appGroups)
if (appGroup.DisplayName != “Project Administrators”) continue;

Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid, new string[] { appGroup.Sid }, QueryMembership.Expanded);

Console.WriteLine(“+{0} ({1} members)”, appGroup.DisplayName, groupMembers.Count());

string members = string.Empty;
foreach (Identity member in groupMembers)
foreach (var memberSid in member.Members)
Identity memberInfo = sec.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.Expanded);
Console.WriteLine(“-{0}”, memberInfo.DisplayName);
Console.WriteLine(“{0};{1}”, teamProject.Name, members);




Written by Mariusz Gorzoch

19 July 2013 at 10:05

Posted in Bez kategorii

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: