Add/Remove users in TFS 2015 using REST API powershell

╄→尐↘猪︶ㄣ 提交于 2019-12-13 10:42:11

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!