使用 REST API powershell 在 TFS 2015 中添加/删除用户 [英] Add/Remove users in TFS 2015 using REST API powershell

查看:31
本文介绍了使用 REST API powershell 在 TFS 2015 中添加/删除用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 REST API 在 TFS 中添加或删除用户.任何帮助表示赞赏.

I want to add or remove users from TFS using REST API. Any help appreciated.

推荐答案

恐怕暂时无法通过 Rest API 实现.如果你真的想以编程方式做到这一点.您可以使用客户端 API.

Afraid this can't be achieved through Rest API for now. If you really want to do it programmatically. You can use client API.

您可以尝试使用 IIdentityManagementService.ReadIdentity() 以及 IIdentityManagementService.AddMemberToApplicationGroup() 将 Windows 用户添加到 TFS 组,即使 TFS 还不知道这些 Windows 用户.

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.

这是通过指定ReadIdentityOptions.IncludeReadFromSource 选项.

This is accomplished by specifying the ReadIdentityOptions.IncludeReadFromSource option.

以下是在 FabrikamFiber 中将 Windows 用户 VSALM\Barry 添加到 Fabrikam Fiber Web 团队(TFS 组)的示例团队项目,在http://vsalm:8080/tfs/FabrikamFiberCollection(也适用于服务器级别)

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);
        }
    }
}

这篇关于使用 REST API powershell 在 TFS 2015 中添加/删除用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆