The following code lists all TFS users over the API.
[System.Diagnostics.DebuggerStepThrough]
private ICredentials GetCredentials()
{
return new NetworkCredential("user", "pwd", "domain");
}
public TfsWrapper()
{
server = new TeamFoundationServer("https://your.tfs.com/tfs/store", GetCredentials());
server.Authenticate();
css = (ICommonStructureService)server.GetService(typeof(ICommonStructureService));
gss = (IGroupSecurityService)server.GetService(typeof(IGroupSecurityService));
tfsIdentities = new List<Identity>();
}
public void ReadTfsUsers()
{
TeamProject tp = this.GetTeamProject();
Identity[] appGroups = gss.ListApplicationGroups(tp.ArtifactUri.AbsoluteUri);
foreach (Identity group in appGroups)
{
Identity[] groupMembers = gss.ReadIdentities(SearchFactor.Sid, new string[] { group.Sid }, QueryMembership.Expanded);
foreach (Identity member in groupMembers)
{
Console.WriteLine(member.DisplayName);
if (member.Members != null)
{
foreach (string memberSid in member.Members)
{
Identity memberInfo = gss.ReadIdentity(SearchFactor.Sid, memberSid, QueryMembership.None);
if (memberInfo.Type == IdentityType.WindowsUser)
{
if (!this.tfsIdentities.Contains(memberInfo))
this.tfsIdentities.Add(memberInfo);
// Console.WriteLine(" {0}", memberInfo.DisplayName);
//Console.WriteLine("AccountName :" + memberInfo.AccountName);
//Console.WriteLine("Deleted :" + memberInfo.Deleted);
//Console.WriteLine("Description :" + memberInfo.Description);
//Console.WriteLine("DisplayName :" + memberInfo.DisplayName);
//Console.WriteLine("DistinguishedName :" + memberInfo.DistinguishedName);
//Console.WriteLine("Domain :" + memberInfo.Domain);
//Console.WriteLine("MailAddress :" + memberInfo.MailAddress);
//Console.WriteLine("Sid :" + memberInfo.Sid);
//Console.WriteLine("Type :" + memberInfo.Type.ToString());
//Console.WriteLine("*********************************");
}
}
}
}
}
}
1 comment:
Great!.
What is GetTeamProject?
Post a Comment