尝试查找与New-AzureADGroupAppRoleAssignment等效的Azure CLI

时间:2020-09-10 04:27:31

标签: azure azure-cli

我找到了一个PowerShell脚本,该脚本可以修改AzureAD组AppRole分配,但无法弄清楚等效的Azure CLI命令是什么。我将在Linux主机上运行这些脚本,因此,我宁愿不要走在这些主机上安装PowerShell的路线,而应直接依靠Azure CLI。

此“任务”的背景是能够动态更新具有其他角色/组的应用程序注册。我可以通过az rest命令为AppRegistration更新appRoles,但是还没有找到从PowerShell cmdlet转换最后一步的方法。

我正在苦苦挣扎的命令:

New-AzureADGroupAppRoleAssignment -ObjectId $myGroup.ObjectId -PrincipalId $myGroup.ObjectId -ResourceId $servicePolicy.ObjectId -Id $myUniqueId

感谢任何帮助/建议!

2 个答案:

答案 0 :(得分:2)

要为组添加角色分配,请使用az role assignment create

首先,获取您的天蓝色广告组对象ID。

az ad group show --group "joeyadgroup"

然后,使用上面获得的objectId将角色分配给该组。

az role assignment create --role "Virtual Machine Contributor" --assignee-object-id xxxxxxxxxxxxxxxxxxxxxxxx

输出如下:

enter image description here

enter image description here

答案 1 :(得分:2)

Azure CLI中没有内置命令,您的选择是使用az rest调用Microsoft Graph-Grant an appRoleAssignment to a group

示例:

az rest --method POST --uri 'https://graph.microsoft.com/v1.0/groups/<object-id of the group>/appRoleAssignments' --headers 'Content-Type=application/json' --body '{"principalId": "principalId-value","resourceId": "resourceId-value","appRoleId": "appRoleId-value"}'

使用的值的含义:

enter image description here

测试结果:

enter image description here