我需要知道如何通过Azure DevOps Server 2022的REST API获取特定组的用户,即on-premise。我们将使用 url 192.168.0.1 和 DefaultCollection 作为示例作为练习目的。 我已经搜索了文档,但是当我尝试将它们应用到我的情况时,它们对我不起作用,我收到 404 Not Found。
现在我正在做:
http://192.168.0.1:8080/tfs/_apis/groupentitlements?api-version=6.0-preview.1 http://192.168.0.1:8080/tfs/DefaultCollection/_apis/groupentitlements?api-version=6.0-preview.1
似乎都不起作用。他们抛出 404。
我不知道它是否与此有关,但我在这个网站上读到“vsaex”前缀用于组权利,“vssps”用于图形,“status”用于状态,所以我尝试了下列: http://vsaex.192.168.0.1:8080/tfs/_apis/groupentitlements?api-version=6.0-preview.1 http://vsaex.192.168.0.1:8080/tfs/DefaultCollection/_apis/groupentitlements?api-version=6.0-preview.1
同样,这两种方法似乎都不起作用。
我还尝试了不同的 api 版本,或者没有使用其中任何一个。我使用 REST API 的其他部分没有任何问题,例如:我可以获取集合中的项目、按项目划分的团队等,并且它们工作得很好。
经过一些研究,我发现通过这个电话你可以得到我正在搜索的内容。
- http://{server:port}/tfs/{collection}/_api/_identity/ReadGroupMembers?scope={groupId}&readMembers=true&api-version=6.0
you can do that.
如果您需要groupId,可以从以下位置获取:
- http://{server:port}/tfs/{collection}/_apis/identities?searchFilter=General&filterValue={group
Name}&api-version=6.0
如果您有超过 1 个名为相同的组,请在响应中搜索您想要的组,在providerDisplayName 属性 -> [{ProjectName}]\{Group Name} 在那里您将获得 groupId,从中您可以获得组的成员
奇怪的是你使用 _api/_identity 而不是 _apis/identities。
您正在查看错误的 API。组权利用于管理 Azure DevOps Services 的许可证,并且不存在于 Azure DevOps Server 的本地版本中。
您正在寻找安全API。
我没有成功
http://{server:port}/tfs/{collection}/_api/_identity/ReadGroupMembers
所以我必须决定使用
http://{server:port}/tfs/{collection}/_api/identies?identityIds
相反。
$Server = 'server:port'
$Org = 'tfs'
$REST = "https://$Server/$Org/_apis"
$ProjectName = '[Project Name]\' #If empty, all projects will be included
$GroupName = 'Group Name'
[Array]$Groups = Invoke-RestMethod (
"$REST/identities?searchFilter=General" +
"&filterValue=$ProjectName$GroupName" +
"&queryMemberShip=Direct" +
"&api-version=5.1"
) |
select -ExpandProperty Value
$Groups | foreach {#convert identityId to Identity
$ThisMemberIdsString = $_.memberIds -join ','
$_.memberIds = Invoke-RestMethod (
"$REST/identities?IdentityIds=$ThisMemberIdsString" +
"&api-version=5.1"
) |
select -ExpandProperty Value
}
$Groups
现在,$Groups.memberIds将包含成员对象而不是memberIds。
(当然,这个脚本可以用更少的行数和更少的变量编写,但为了在示例中清晰起见,我更喜欢这种格式。)