Azure CLI相当于Powershell的AddMsolRoleMemb

2024-04-24 22:03:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Azure CLI 2.0并试图找到与以下Powershell命令等效的命令:

Add-MsolRoleMember -RoleObjectID $roleID -RoleMemberType ServicePrincipal -RoleMemberObjectId $appObjectId

我使用此命令将Azure AD应用程序主体添加到“用户帐户管理员”角色。在

我使用这个链接来安装MSOL Powershell libraries,其中包括“addmsolrolemember”命令。在

因为我需要在Mac、Linux等上运行的命令,所以我尝试使用最新版本的“Azure CLI”,尽管我对其他代码示例(例如Python)持开放态度。在

以下是迄今为止我尝试过的cli命令:

^{pr2}$

所以我的问题是:如何使用CLI或其他在Mac、Linux等上运行的库向app主体添加角色。?在


Tags: 命令add角色clilinuxmacazure主体
2条回答

一篇好文章可以在这里找到:https://blogs.msdn.microsoft.com/aaddevsup/2018/08/29/how-to-add-an-azure-ad-role-to-a-enterprise-application-service-principal/

代码如下:

# Fetch User Account Administrator role instance
$role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'User Account Administrator'}

# If role instance does not exist, instantiate it based on the role template
if ($role -eq $null) {
    # Instantiate an instance of the role template
    $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object {$_.displayName -eq 'User Account Administrator'}
    Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId

    # Fetch User Account Administrator role instance again
    $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'User Account Administrator'}
}

#Now that we have the object IDs for the AAD role, we will need to get both object IDs to add the role to the enterprise application. We can use the command below :
Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId $BeckeChB2Cs0v1GraphApiAdSPN.ObjectId

不幸的是,据我所知,在Linux上没有可以添加成员到Azure组织角色的库工作。在

目前,我们可以使用Azure CLI 2.0来管理Azure AD用户应用程序服务主体,但我们无法使用CLI 2.0向Azure组织角色添加成员。在

az role assignment create  assignee <my app id>   role <role id>

此命令az role assignment用于管理资源组角色。例如,我们希望授予用户所有者权限。我们可以在以下截图中通过Azure门户找到此角色: enter image description here

关于组织角色,我们可以在这个官方的article中找到他们,比如计费管理员合规管理员。与资源组权限不同。在

您可以将您的反馈发送到此link,您在该链接中共享的所有反馈都将由Microsoft工程团队监视和审阅。在

===========
更新: enter image description here

相关问题 更多 >