【问题标题】:VSTS - Getting al Team Project Administrators using VSTS REST APIVSTS - 使用 VSTS REST API 获取团队项目管理员
【发布时间】:2017-11-28 12:41:59
【问题描述】:

是否可以让每个项目的所有项目管理员?我发现我可以使用此 API 获取所有项目及其团队成员:https://www.visualstudio.com/en-us/docs/integrate/api/tfs/teams#get-a-teams-members

但随后我得到了团队项目成员的完整列表,而不是他们的权限。我想要一个管理员列表,以便我可以就他们的 TeamProject 与他们联系。

提前致谢!

顺便说一句,使用 TFS 2017

【问题讨论】:

    标签: rest api tfs azure-devops


    【解决方案1】:

    目前没有这样的 REST API 可以从 VSTS 组(例如项目管理员)中获取成员。

    但是有一个用户声音REST API for a better Projects and Team Management在建议中包含类似的功能,你可以投票和跟进。

    【讨论】:

      【解决方案2】:

      无法通过 Rest API 实现,但可以通过 SOAP API 实现。以下是代码示例供您参考:

      using System;
      using Microsoft.TeamFoundation.Client;
      using Microsoft.TeamFoundation.Framework.Client;
      using Microsoft.TeamFoundation.Framework.Common;
      
      namespace GetAdmin
      {
          class Program
          {
              static void Main(string[] args)
              {
                  string projectname = "projectname";
                  string groupname = $"[{projectname}]\\Project Administrators";
                  TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri("https://vstsaccount.visualstudio.com/"));
                  IIdentityManagementService idms = ttpc.GetService<IIdentityManagementService>();
                  TeamFoundationIdentity admingroup = idms.ReadIdentity(IdentitySearchFactor.AccountName,groupname,MembershipQuery.Direct,ReadIdentityOptions.IncludeReadFromSource);
                  foreach (IdentityDescriptor tfi in admingroup.Members)
                  {
                      TeamFoundationIdentity member = idms.ReadIdentity(tfi,MembershipQuery.Expanded, ReadIdentityOptions.ExtendedProperties);
                      Console.WriteLine(member.DisplayName);
                      Console.WriteLine(member.GetProperty("Mail"));
                  }
                  Console.ReadLine();
              }
          }
      }
      

      Powershell 脚本:

      $dllpath1 = "D:\\net45\\Microsoft.TeamFoundation.Client.dll";
      $dllpath2 = "D:\\net45\\Microsoft.TeamFoundation.Common.dll";
      $dllpath3 = "D:\\net45\\Microsoft.VisualStudio.Services.Common.dll";
      $dllpath4 = "D:\\net45\\Microsoft.VisualStudio.Services.Client.Interactive.dll";
      
      [System.Reflection.Assembly]::LoadFrom($dllpath1);
      [System.Reflection.Assembly]::LoadFrom($dllpath2);
      [System.Reflection.Assembly]::LoadFrom($dllpath3);
      [System.Reflection.Assembly]::LoadFrom($dllpath4);
      
          $uri = "https://xxx.visualstudio.com/";
          $tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri)
          $idservice = $tfs.GetService("Microsoft.TeamFoundation.FrameWork.Client.IIdentityManagementService")
          $projectname = "xxx"
          $groupname = "[" + $projectname + "]\Project Administrators";
          $admingroup = $idservice.ReadIdentity([Microsoft.TeamFoundation.FrameWork.Common.IdentitySearchFactor]::AccountName,$groupname,[Microsoft.TeamFoundation.FrameWork.Common.MembershipQuery]::Direct,[Microsoft.TeamFoundation.FrameWork.Common.ReadIdentityOptions]::IncludeReadFromSource)
          foreach ($id in $admingroup.Members)
          {
              $member = $idservice.ReadIdentity($id,[Microsoft.TeamFoundation.FrameWork.Common.MembershipQuery]::Expanded, [Microsoft.TeamFoundation.FrameWork.Common.ReadIdentityOptions]::ExtendedProperties)
              Write-Host $member.DisplayName
              Write-Host $member.GetProperty("Mail")
          }
      

      【讨论】:

      • 您好,谢谢!可悲的是,我无法访问 TFS 服务器,因此不可能包含上面列出的模块。另外,我不掌握 C#(是吗?)我需要能够使用 powershell 或 python(从命令行)来做到这一点,因为我将使用 Cronacle(企业调度程序)来安排它。
      • @EricJansen 它们是我们为开发人员发布的 .Net 客户端库,您不需要访问 TFS 服务器。只需通过 nuget 安装即可:docs.microsoft.com/en-us/vsts/integrate/concepts/…
      • @EricJansen 我添加了 powershell 脚本供您参考。它使用团队资源管理器中的凭据,因此您必须先连接到团队资源管理器中的 VSTS 帐户,然后运行脚本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-01
      • 1970-01-01
      • 2018-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多