將 Microsoft Entra 角色指派給群組
若要簡化角色管理,您可以將 Microsoft Entra 角色指派給群組,而不是個人。 本文說明如何使用 Microsoft Entra 系統管理中心、PowerShell 或 Microsoft Graph API,將 Microsoft Entra 角色指派給 可指派角色的群組 。
必要條件
- Microsoft Entra ID P1 授權
- 特殊許可權角色 管理員 istrator 角色
- 使用 Microsoft Graph PowerShell 時的 Microsoft.Graph 模組
- 使用 Azure AD PowerShell 時,Azure AD PowerShell 模組
- 針對 Microsoft Graph API 使用 Graph 總管時的管理員同意
如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。
Microsoft Entra 系統管理中心
提示
本文中的步驟可能會根據您從開始的入口網站稍有不同。
將 Microsoft Entra 角色指派給群組類似於指派用戶和服務主體,不同之處在於只能使用可指派角色的群組。
提示
這些步驟適用於具有 Microsoft Entra ID P1 授權的客戶。 如果您的租使用者中有 Microsoft Entra ID P2 授權,您應該改為遵循在 Privileged Identity Management 中指派 Microsoft Entra 角色中的步驟。
以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心。
流覽至 [身分>識別角色] 和 [系統管理員>角色] 和 [系統管理員]。
選取角色名稱以開啟角色。 請勿在角色旁邊新增複選標記。
選取 [新增指派]。
如果您看到與下列螢幕快照不同的內容,您可能會有 Microsoft Entra ID P2。 如需詳細資訊,請參閱 在 Privileged Identity Management 中指派 Microsoft Entra 角色。
選取您要指派給此角色的群組。 只會顯示可指派角色的群組。
如果未列出群組,您必須建立可指派角色的群組。 如需詳細資訊,請參閱 在 Microsoft Entra ID 中建立可指派角色的群組。
選取 [ 新增 ] 將角色指派給群組。
PowerShell
建立可指派角色的群組
使用 New-MgGroup 命令來建立可指派角色的群組。
Connect-MgGraph -Scopes "Group.ReadWrite.All","RoleManagement.ReadWrite.Directory"
$group = New-MgGroup -DisplayName "Contoso_Helpdesk_Administrators" -Description "This group has Helpdesk Administrator built-in role assigned to it in Azure AD." -MailEnabled:$false -SecurityEnabled -MailNickName "contosohelpdeskadministrators" -IsAssignableToRole:$true
取得您想要指派的角色定義
使用 Get-MgRoleManagementDirectoryRoleDefinition 命令來取得角色定義。
$roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Helpdesk Administrator'"
建立角色指派
使用 New-MgRoleManagementDirectoryRoleAssignment 命令來指派角色。
$roleAssignment = New-MgRoleManagementDirectoryRoleAssignment -DirectoryScopeId '/' -RoleDefinitionId $roleDefinition.Id -PrincipalId $group.Id
Microsoft Graph API
建立可指派角色的群組
使用建立 群組 API 來建立可指派角色的群組。
要求
POST https://graph.microsoft.com/v1.0/groups
{
"description": "This group is assigned to Helpdesk Administrator built-in role of Azure AD.",
"displayName": "Contoso_Helpdesk_Administrators",
"groupTypes": [
"Unified"
],
"isAssignableToRole": true,
"mailEnabled": true,
"mailNickname": "contosohelpdeskadministrators",
"securityEnabled": true
}
回應
HTTP/1.1 201 Created
取得您想要指派的角色定義
使用 List unifiedRoleDefinitions API 來取得角色定義。
要求
GET https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions?$filter = displayName eq 'Helpdesk Administrator'
回應
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleDefinitions",
"value": [
{
"id": "729827e3-9c14-49f7-bb1b-9608f156bbb8",
"description": "Can reset passwords for non-administrators and Helpdesk Administrators.",
"displayName": "Helpdesk Administrator",
"isBuiltIn": true,
"isEnabled": true,
"resourceScopes": [
"/"
],
...
建立角色指派
使用建立 unifiedRoleAssignment API 來指派角色。
要求
POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
{
"@odata.type": "#microsoft.graph.unifiedRoleAssignment",
"principalId": "<Object ID of Group>",
"roleDefinitionId": "<ID of role definition>",
"directoryScopeId": "/"
}
回應
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#roleManagement/directory/roleAssignments/$entity",
"id": "<Role assignment ID>",
"roleDefinitionId": "<ID of role definition>",
"principalId": "<Object ID of Group>",
"directoryScopeId": "/"
}