0
votes

Is it possible to get all project administrators per project? I found out I can get all projects and their team members using this API: https://www.visualstudio.com/en-us/docs/integrate/api/tfs/teams#get-a-teams-members

But then I get a full list of members of the Team Project, and not their permissions. I want to have a list of administrators, so that I can contact them about their TeamProject.

Thanks in advance!

BTW, using TFS 2017

2

2 Answers

0
votes

There is no such REST API to get members from a VSTS group (such as Project Administrators) for now.

But there has an user voice REST API for a better Projects and Team Management which contains similar function in the suggestions, you can vote and follow up.

0
votes

It cannot be achieved via Rest API, but it can be achieved with SOAP API. Following is the code sample for your reference:

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 Script:

$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")
    }