Powershell 向Azure DevOps团队添加成员
我能够获得团队或团队成员,但我无法找到向团队添加用户的方法。是否有RESt_API、命令行或API,我可以使用域名“domain\user”将用户添加到团队中。请告知。非常感谢Powershell 向Azure DevOps团队添加成员,powershell,command-line,tfs,azure-devops,Powershell,Command Line,Tfs,Azure Devops,我能够获得团队或团队成员,但我无法找到向团队添加用户的方法。是否有RESt_API、命令行或API,我可以使用域名“domain\user”将用户添加到团队中。请告知。非常感谢 最好的祝愿,如果您使用Azure DevOps服务(),您可以使用REST API 如果使用Azure DevOps服务器,则不会记录用于向项目和团队添加成员的REST API。作为一种解决方法,我们可以通过在浏览器中按F12,然后选择Network来跟踪此RESTAPI 样本: POST http://TFS2019:
最好的祝愿,如果您使用Azure DevOps服务(),您可以使用REST API
如果使用Azure DevOps服务器,则不会记录用于向项目和团队添加成员的REST API。作为一种解决方法,我们可以通过在浏览器中按
F12
,然后选择Network
来跟踪此RESTAPI
样本:
POST http://TFS2019:8080/tfs/{Collection}/{project}/_api/_identity/AddIdentities?api-version=5.0
Request Body:
{
"newUsersJson": "[]",
"existingUsersJson": "[\"55b98726-c6f5-48d2-976b-xxxxxx\"]",
"groupsToJoinJson": "[\"7283653f-54b2-4ebf-86c3-xxxxxxx\"]",
"aadGroupsJson": "[]"
}
但是,正如我们所看到的,我们只能在请求json正文中使用用户和团队/组GUID。对于特定的团队/组,我们可以使用和团队获取其GUID。
对于用户来说,实际上它使用的是TeamFoundationId
,当用户添加到Azure DevOps服务器时,会自动生成唯一的TeamFoundationId
。我们无法使用外部工具生成ID
因此,要使用RESTAPI,我们需要获取要将其添加到项目/团队的特定用户的TeamFoundationId
目前,Azure DevOps Server 2019中没有REST API列出用户的TeamFoundationId
,但是我们可以通过客户端API获得它:
以下示例供您参考,以获取特定用户的TeamFoundationId
(它还将用户列表及其TeamFoundationId
导出到userlist.txt
)
使用系统;
使用Microsoft.TeamFoundation.Client;
使用Microsoft.TeamFoundation.Framework.Client;
使用Microsoft.TeamFoundation.Framework.Common;
使用System.Linq;
使用System.IO;
命名空间Getuserlist
{
班级计划
{
静态void Main(字符串[]参数)
{
TfsConfigurationServer tcs=新TfsConfigurationServer(新Uri(“https://wsicads2019"));
IIdentialManagementService ims=tcs.GetService();
TeamFoundationIdentity tfi=ims.ReadIdentity(IdentitySearchFactor.AccountName,“[DefaultCollection]\\项目集合有效用户”,MembershipQuery.Expanded,ReadIdentityOptions.None);
TeamFoundationIdentity[]ids=ims.ReadIdentity(tfi.Members,MembershipQuery.None,ReadIdentityOptions.None);
使用(StreamWriter file=newstreamwriter(“userlist.txt”))
foreach(ids中的TeamFoundationIdentity id)
{
if(id.Descriptor.IdentityType==“System.Security.Principal.WindowsIdentity”&&id.UniqueName==“Domain\\User”)
{Console.WriteLine(“[{0},{1}]”,id.UniqueName,id.TeamFoundationId);}
WriteLine(“[{0},{1}]”,id.UniqueName,id.TeamFoundationId);
}
var count=ids.count(x=>ids.Contains(x));
控制台写入线(计数);
Console.ReadLine();
}
}
}
哪个版本?Azure DevOps服务?你已经看过了吗?你看过我的回复了吗?有帮助吗?
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System.Linq;
using System.IO;
namespace Getuserlist
{
class Program
{
static void Main(string[] args)
{
TfsConfigurationServer tcs = new TfsConfigurationServer(new Uri("https://wsicads2019"));
IIdentityManagementService ims = tcs.GetService<IIdentityManagementService>();
TeamFoundationIdentity tfi = ims.ReadIdentity(IdentitySearchFactor.AccountName, "[DefaultCollection]\\Project Collection Valid Users", MembershipQuery.Expanded, ReadIdentityOptions.None);
TeamFoundationIdentity[] ids = ims.ReadIdentities(tfi.Members, MembershipQuery.None, ReadIdentityOptions.None);
using (StreamWriter file = new StreamWriter("userlist.txt"))
foreach (TeamFoundationIdentity id in ids)
{
if (id.Descriptor.IdentityType == "System.Security.Principal.WindowsIdentity" && id.UniqueName == "Domain\\User")
{ Console.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId); }
file.WriteLine("[{0},{1}]", id.UniqueName, id.TeamFoundationId);
}
var count = ids.Count(x => ids.Contains(x));
Console.WriteLine(count);
Console.ReadLine();
}
}
}