Share via


在不同範圍指派 Microsoft Entra 角色

在 Microsoft Entra 識別符中,您通常會指派 Microsoft Entra 角色,使其套用至整個租使用者。 不過,您也可以為不同的資源指派 Microsoft Entra 角色,例如系統管理單位或應用程式註冊。 例如,您可以指派 Helpdesk 管理員 istrator 角色,使其只套用至特定的系統管理單位,而非整個租使用者。 角色指派套用的資源也稱為範圍。 本文說明如何在租使用者、管理單位和應用程式註冊範圍指派 Microsoft Entra 角色。 如需範圍的詳細資訊,請參閱 Microsoft Entra ID 中的角色型存取控制 (RBAC) 概觀。

必要條件

  • 特殊許可權角色 管理員 istrator。
  • 使用 PowerShell 時安裝的 Microsoft Graph PowerShell SDK。
  • 使用適用於 Microsoft Graph API 的 Graph 總管時,管理員 同意。

如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。

將範圍指派給租使用者的角色

本節說明如何在租用戶範圍指派角色。

Microsoft Entra 系統管理中心

提示

本文中的步驟可能會根據您從開始的入口網站稍有不同。

  1. 以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別角色] 和 [系統管理員>角色] 和 [系統管理員]。

    Microsoft Entra ID 中的角色和系統管理員頁面。

  3. 選取角色以查看其指派。 若要協助您尋找所需的角色,請使用 [新增篩選 ] 來篩選角色。

  4. 選取 [ 新增指派 ],然後選取您要指派給此角色的使用者。

    新增所選角色的 [指派] 窗格。

  5. 選取 [ 新增 ] 以指派角色。

PowerShell

請遵循下列步驟,使用 PowerShell 指派 Microsoft Entra 角色。

  1. 開啟 PowerShell 視窗。 如有必要,請使用 Install-Module 來安裝 Microsoft Graph PowerShell。 如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。

    Install-Module Microsoft.Graph -Scope CurrentUser
    
  2. 在 PowerShell 視窗中,使用 連線-MgGraph 登入您的租使用者。

    Connect-MgGraph -Scopes "RoleManagement.Read.Directory","User.Read.All","RoleManagement.ReadWrite.Directory"
    
  3. 使用 Get-MgUser 取得使用者。

    $user = Get-MgUser -Filter "userPrincipalName eq 'alice@contoso.com'"
    
  4. 使用 Get-MgRoleManagementDirectoryRoleDefinition 取得您想要指派的角色。

    $roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition -Filter "displayName eq 'Billing Administrator'"
    
  5. 將租用戶設定為角色指派的範圍。

    $directoryScope = '/'
    
  6. 使用 New-MgRoleManagementDirectoryRoleAssignment 來指派角色。

    $roleAssignment = New-MgRoleManagementDirectoryRoleAssignment `
       -DirectoryScopeId $directoryScope -PrincipalId $user.Id `
       -RoleDefinitionId $roleDefinition.Id
    

Microsoft Graph API

請遵循這些指示,在 Graph 總管中使用 Microsoft Graph API 來指派角色。

  1. 登入 Graph 總管

  2. 使用 列出使用者 API 來取得使用者。

    GET https://graph.microsoft.com/v1.0/users?$filter=userPrincipalName eq 'alice@contoso.com'
    
  3. 使用 List unifiedRoleDefinitions API 來取得您想要指派的角色。

    GET https://graph.microsoft.com/v1.0/rolemanagement/directory/roleDefinitions?$filter=displayName eq 'Billing Administrator'
    
  4. 使用建立 unifiedRoleAssignment API 來指派角色。

    POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
    {
        "@odata.type": "#microsoft.graph.unifiedRoleAssignment",
        "principalId": "<provide objectId of the user obtained above>",
        "roleDefinitionId": "<provide templateId of the role obtained above>",
        "directoryScopeId": "/"
    }
    

將範圍設定為系統管理單位的角色

本節說明如何在管理單位範圍指派角色

Microsoft Entra 系統管理中心

  1. 以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別角色與系統管理員> 管理員 單位]。

  3. 選取管理單位。

    microsoft Entra ID 中的 管理員 單位。

  4. 從左側導覽功能表中選取 [角色和系統管理員 ],以查看可透過系統管理單位指派的所有角色清單。

    Microsoft Entra ID 中 [系統管理單位] 底下的 [角色和系統管理員] 功能表。

  5. 選取所需的角色。

  6. 選取 [新增指派 ],然後選取您要指派此角色的使用者或群組。

  7. 選取 [ 新增 ] 以指派範圍在管理單位上的角色。

注意

您不會在這裡看到 Microsoft Entra 內建或自定義角色的完整清單。 這是預期行為。 我們顯示具有與管理單位內支援之物件相關許可權的角色。 若要查看管理單位內支持的物件清單,請參閱 Microsoft Entra ID 中的 管理員 單位。

PowerShell

請遵循下列步驟,使用 PowerShell 在系統管理單位範圍指派 Microsoft Entra 角色。

  1. 開啟 PowerShell 視窗。 如有必要,請使用 Install-Module 來安裝 Microsoft Graph PowerShell。 如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。

    Install-Module Microsoft.Graph -Scope CurrentUser
    
  2. 在 PowerShell 視窗中,使用 連線-MgGraph 登入您的租使用者。

    Connect-MgGraph -Scopes "Directory.Read.All","RoleManagement.Read.Directory","User.Read.All","RoleManagement.ReadWrite.Directory"
    
  3. 使用 Get-MgUser 取得使用者。

    $user = Get-MgUser -Filter "userPrincipalName eq 'alice@contoso.com'"
    
  4. 使用 Get-MgRoleManagementDirectoryRoleDefinition 取得您想要指派的角色。

    $roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition `
       -Filter "displayName eq 'User Administrator'"
    
  5. 使用 Get-MgDirectory 管理員 istrativeUnit 取得您想要將角色指派範圍設定為的系統管理單位。

    $adminUnit = Get-MgDirectoryAdministrativeUnit -Filter "displayName eq 'Seattle Admin Unit'"
    $directoryScope = '/administrativeUnits/' + $adminUnit.Id
    
  6. 使用 New-MgRoleManagementDirectoryRoleAssignment 來指派角色。

    $roleAssignment = New-MgRoleManagementDirectoryRoleAssignment `
       -DirectoryScopeId $directoryScope -PrincipalId $user.Id `
       -RoleDefinitionId $roleDefinition.Id
    

Microsoft Graph API

請遵循這些指示,在 Graph 總管中使用 Microsoft Graph API 在系統管理單位範圍中指派角色。

  1. 登入 Graph 總管

  2. 使用 列出使用者 API 來取得使用者。

    GET https://graph.microsoft.com/v1.0/users?$filter=userPrincipalName eq 'alice@contoso.com'
    
  3. 使用 List unifiedRoleDefinitions API 來取得您想要指派的角色。

    GET https://graph.microsoft.com/v1.0/rolemanagement/directory/roleDefinitions?$filter=displayName eq 'User Administrator'
    
  4. 使用 List administrativeUnits API 取得您想要將角色指派範圍設定為的系統管理單位。

    GET https://graph.microsoft.com/v1.0/directory/administrativeUnits?$filter=displayName eq 'Seattle Admin Unit'
    
  5. 使用建立 unifiedRoleAssignment API 來指派角色。

    POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
    {
        "@odata.type": "#microsoft.graph.unifiedRoleAssignment",
        "principalId": "<provide objectId of the user obtained above>",
        "roleDefinitionId": "<provide templateId of the role obtained above>",
        "directoryScopeId": "/administrativeUnits/<provide objectId of the admin unit obtained above>"
    }
    

注意

在這裡,directoryScopeId 會指定為 /administrativeUnits/foo,而不是 /foo。 這是依設計。 /administrativeUnits/foo 範圍表示主體可以管理管理單位的成員(根據指派的角色),而不是管理單位本身。 /foo 的範圍表示主體可以管理 Microsoft Entra 物件本身。 在後續章節中,您會看到範圍是 /foo ,因為應用程式註冊上設定的角色會授與管理物件本身的許可權。

指派範圍設定為應用程式註冊的角色

本節說明如何在應用程式註冊範圍指派角色。

Microsoft Entra 系統管理中心

  1. 以至少 [特殊權限角色管理員] 身分登入 Microsoft Entra 系統管理中心

  2. 流覽至 [身分>識別應用程式> 應用程式註冊]。

  3. 選取應用程式。 您可以使用搜尋方塊來尋找所需的應用程式。

    Microsoft Entra ID 中的 應用程式註冊。

  4. 從左側導覽功能表中選取 [角色和系統管理員 ],以查看可透過應用程式註冊指派的所有角色清單。

    Microsoft Entra ID 中應用程式註冊的角色。

  5. 選取所需的角色。

  6. 選取 [新增指派 ],然後選取您要指派此角色的使用者或群組。

    在 Microsoft Entra ID 中,將範圍設定為應用程式註冊的角色指派。

  7. 選取 [ 新增 ] 以指派範圍在應用程式註冊上的角色。

    已成功在 Microsoft Entra ID 中將範圍設定為應用程式註冊的角色指派。

    在 Microsoft Entra ID 中指派給使用者指派給應用程式註冊的角色。

注意

您不會在這裡看到 Microsoft Entra 內建或自定義角色的完整清單。 這是預期行為。 我們顯示具有僅管理應用程式註冊相關許可權的角色。

PowerShell

請遵循下列步驟,使用PowerShell在應用程式範圍指派 Microsoft Entra 角色。

  1. 開啟 PowerShell 視窗。 如有必要,請使用 Install-Module 來安裝 Microsoft Graph PowerShell。 如需詳細資訊,請參閱 使用PowerShell或 Graph 總管的必要條件。

    Install-Module Microsoft.Graph -Scope CurrentUser
    
  2. 在 PowerShell 視窗中,使用 連線-MgGraph 登入您的租使用者。

    Connect-MgGraph -Scopes "Application.Read.All","RoleManagement.Read.Directory","User.Read.All","RoleManagement.ReadWrite.Directory"
    
  3. 使用 Get-MgUser 取得使用者。

    $user = Get-MgUser -Filter "userPrincipalName eq 'alice@contoso.com'"
    
  4. 使用 Get-MgRoleManagementDirectoryRoleDefinition 取得您想要指派的角色。

    $roleDefinition = Get-MgRoleManagementDirectoryRoleDefinition `
       -Filter "displayName eq 'Application Administrator'"
    
  5. 使用 Get-MgApplication 取得您想要將角色指派範圍設定為的應用程式註冊。

    $appRegistration = Get-MgApplication -Filter "displayName eq 'f/128 Filter Photos'"
    $directoryScope = '/' + $appRegistration.Id
    
  6. 使用 New-MgRoleManagementDirectoryRoleAssignment 來指派角色。

    $roleAssignment = New-MgRoleManagementDirectoryRoleAssignment `
       -DirectoryScopeId $directoryScope -PrincipalId $user.Id `
       -RoleDefinitionId $roleDefinition.Id 
    

Microsoft Graph API

請遵循這些指示,在圖形總管中使用 Microsoft Graph API 在應用程式範圍中指派角色。

  1. 登入 Graph 總管

  2. 使用 列出使用者 API 來取得使用者。

    GET https://graph.microsoft.com/v1.0/users?$filter=userPrincipalName eq 'alice@contoso.com'
    
  3. 使用 List unifiedRoleDefinitions API 來取得您想要指派的角色。

    GET https://graph.microsoft.com/v1.0/rolemanagement/directory/roleDefinitions?$filter=displayName eq 'Application Administrator'
    
  4. 使用清單應用程式 API 取得您想要將角色指派範圍設定為的系統管理單位。

    GET https://graph.microsoft.com/v1.0/applications?$filter=displayName eq 'f/128 Filter Photos'
    
  5. 使用建立 unifiedRoleAssignment API 來指派角色。

    POST https://graph.microsoft.com/v1.0/roleManagement/directory/roleAssignments
    
    {
        "@odata.type": "#microsoft.graph.unifiedRoleAssignment",
        "principalId": "<provide objectId of the user obtained above>",
        "roleDefinitionId": "<provide templateId of the role obtained above>",
        "directoryScopeId": "/<provide objectId of the app registration obtained above>"
    }
    

注意

此處的 directoryScopeId 會指定為 /foo,與上述區段不同。 這是依設計。 /foo 的範圍表示主體可以管理該 Microsoft Entra 物件。 /administrativeUnits/foo 範圍表示主體可以管理管理單位的成員(根據指派的角色),而不是管理單位本身。

下一步