问题
I want to add or remove users from TFS using REST API. Any help appreciated.
回答1:
Afraid this can't be achieved through Rest API for now. If you really want to do it programmatically. You can use client API.
You can try to 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
(Also applies to server level)
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);
}
}
}
来源:https://stackoverflow.com/questions/39590143/add-remove-users-in-tfs-2015-using-rest-api-powershell