Azure active directory 将自定义Azure AD角色分配给安全组

Azure active directory 将自定义Azure AD角色分配给安全组,azure-active-directory,Azure Active Directory,我已经创建了一个自定义Azure AD角色,用于读取目录中的服务主体。这样用户就可以排除故障,而无需寻求其他支持。但是,我无法将此自定义角色分配给整个安全组。如何将此角色分配给组中的所有用户?您可以使用powershell将此角色分配给组中的所有用户,请尝试下面的脚本 首先,您需要安装powershell模块 Install-Module -Name AzureADPreview 连接AzureAD $members=获取AzureADGroupMember-ObjectId“” $role

我已经创建了一个自定义Azure AD角色,用于读取目录中的服务主体。这样用户就可以排除故障,而无需寻求其他支持。但是,我无法将此自定义角色分配给整个安全组。如何将此角色分配给组中的所有用户?

您可以使用powershell将此角色分配给组中的所有用户,请尝试下面的脚本

首先,您需要安装powershell模块

Install-Module -Name AzureADPreview

连接AzureAD
$members=获取AzureADGroupMember-ObjectId“”
$roleDefinition=获取AzureADMSRoleDefinition-筛选“displayName eq”
#获取应用程序注册并构造分配的资源范围。
$appRegistration=获取AzureADApplication-筛选“displayName eq'joyttt'”
$resourceScope='/'+$appRegistration.objectId
foreach($members中的成员){
新AzureADMSRoleAssignment-ResourceScope$ResourceScope-RoleDefinitionId$roleDefinition.Id-PrincipalId$member.ObjectId
}


参考-

感谢您的输入。我一直使用Azure AD powershell模块,但没有考虑使用此方法分配角色。非常感谢您的帮助。@ekbrothers注意到它是
AzureADPreview
模块,它不同于
AzureAD
模块,如果您安装了
AzureAD
模块,请先卸载
AzureAD
模块,使用
uninstall module-Name AzureAD
,然后安装
AzureADPreview
模块。
Connect-AzureAD

$members = Get-AzureADGroupMember -ObjectId "<ObjectId of the Security Group>"
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq '<Custom role name>'"

# Get app registration and construct resource scope for assignment.
$appRegistration = Get-AzureADApplication -Filter "displayName eq 'joyttt'"
$resourceScope = '/' + $appRegistration.objectId

foreach($member in $members){
    New-AzureADMSRoleAssignment -ResourceScope $resourceScope -RoleDefinitionId $roleDefinition.Id -PrincipalId $member.ObjectId
}