powershell - 将成员添加到 Azure DevOps 团队
问题描述
我已经能够获得团队或团队成员,但我无法将用户添加到团队中。是否有我可以使用域名“domain\user”将用户添加到团队的 REST_API、命令行或 API。请指教。非常感谢
此致,
解决方案
如果您使用 Azure DevOps 服务 ( https://dev.azure.com/xxxx ),您可以使用成员 - 添加REST API。
如果使用 Azure DevOps Server,则未记录用于将成员添加到项目和团队的 REST API。作为一种解决方法,我们可以通过F12
在浏览器中按下然后选择来跟踪这个 rest api Network
。
样本:
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。对于特定的团队/组,我们可以使用REST API 项目和团队来获取他们的 GUID。对于用户而言,实际上是使用,将用户添加到 Azure DevOps Server 时会自动生成TeamFoundationId
唯一性。TeamFoundationId
我们无法使用外部工具生成 ID。
因此,要使用该 REST API,我们需要获取TeamFoundationId
您想要将其添加到项目/团队的特定用户。
目前,没有 REST API 来列出TeamFoundationId
Azure DevOps Server 2019 中的用户,但是我们可以使用 Client API 获取它:
下面的示例供您参考以获取TeamFoundationId
特定用户的:(它还将导出用户列表及其TeamFoundationId
到userlist.txt
)
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();
}
}
}
推荐阅读
- datastage - 我想在 datastage 中转换为日期时间格式
- cmake - 在 CMAKE 中指定运行时和构建时依赖项
- mysql - 未向列中插入任何值导致 MySQL 数据库出错
- swift - 操作员的结果 - 未使用 swift reduce
- java - 具有复合键的树数据
- kubernetes - 自己机架上的 Kubernetes 持久卷
- ssl - 播放框架看不到 SSL 中间/链证书
- vb.net - 如何比较 4 个不同的值?
- azure-service-fabric - 在 Service Fabric [本地] 中调用远程服务时出现 FileNotFoundException
- php - 使用动态子元素从 xml 元素中获取数据