In TFS2012, the IGroupSecurityService
was marked obsolete and replaced with IIdentityManagementService
.
You can use IIdentityManagementService.ReadIdentity()
along with IIdentityManagementService.AddMemberToApplicationGroup()
to add Windows users to TFS groups, even if those Windows users are not known to TFS yet.
This is accomplished by specifying the ReadIdentityOptions.IncludeReadFromSource
option.
Below is an example of adding a Windows user VSALM\Barry
to the Fabrikam Fiber Web Team
(TFS Group), in the FabrikamFiber
Team Project, in the http://vsalm:8080/tfs/FabrikamFiberCollection
server/collection.
You will need to add references to: Microsoft.TeamFoundation.Client
and Microsoft.TeamFoundation.Common
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://vsalm:8080/tfs/FabrikamFiberCollection"));
var ims = tpc.GetService<IIdentityManagementService>();
var tfsGroupIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"[FabrikamFiber]\\Fabrikam Fiber Web Team",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
var userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"VSALM\\Barry",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
ims.AddMemberToApplicationGroup(tfsGroupIdentity.Descriptor, userIdentity.Descriptor);
}
}
}