Hi all,
I have created a console application which gives us all the groups of a team Project. I am able to retrieve all the TFS groups.
The code is :-
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ListGroupMember
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter TFS server or project collection Url");
string servername = Console.ReadLine();
Console.WriteLine("Enter Team Project Name");
string TeamProjectName = Console.ReadLine();
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri(servername));
tfs.EnsureAuthenticated();
//1.Get the Idenitity Management Service
IIdentityManagementService ims = tfs.GetService<IIdentityManagementService>();
//Find all the team projects in the collection and save in array of type ProjectInfo
TfsTeamProjectCollection projCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(servername));
ICommonStructureService Iss = (ICommonStructureService)projCollection.GetService(typeof(ICommonStructureService));
ProjectInfo[] ProjInfo = Iss.ListProjects();
//Another way to get all team projects
// Version control service exposes methods to work with TFS version control
var vcs = tfs.GetService<VersionControlServer>();
// Since we'll be reporting groups for all team projects, imp to get all team projects
var teamProjects = vcs.GetAllTeamProjects(false);
//Get all Application groups
// Group Security service exposes methods to get groups, users and security details
var sec = tfs.GetService<IGroupSecurityService>();
// Store TFS Group name in an array of type string
string[] tfsGroupName = { "Build Administrators", "Contributors", "Project Administrators", "Readers", "Endpoint Administrators","Endpoint
Creators","Release Administrators" };
foreach( var teamProject in teamProjects)
{
if (TeamProjectName == teamProject.Name)
{
Identity[] appGroups = sec.ListApplicationGroups(teamProject.ArtifactUri.AbsoluteUri);
// Identity[] appGroups = sec.ListApplicationGroups("vstfs:///Classification/TeamProject/c339ff13-89db-4a33-977c-63988e4e645e");
//Get all members in application group
foreach (Identity group in appGroups)
{
if(tfsGroupName.Contains(group.AccountName))
{
Identity[] groupMembers = sec.ReadIdentities(SearchFactor.Sid,
new string[] { group.Sid }, QueryMembership.Expanded);
foreach (Identity member in groupMembers)
{
}
}
}
}
}
}
}
}
But I am unable to find the members of the group. How can I do this.
Please help. Thanks for assistance.