共用方式為


控管不支援布建的應用程式使用者 - Microsoft PowerShell

有三個常見案例,在您將應用程式與 Microsoft Entra ID 控管 存取權檢閱功能搭配使用應用程式之前,必須先將 Microsoft Entra ID 填入應用程式的現有使用者。

  • 使用自己的識別提供者之後,移轉至 Microsoft Entra 標識碼的應用程式
  • 未使用 Microsoft Entra ID 做為其唯一識別提供者的應用程式
  • 應用程式不會使用 Microsoft Entra ID 作為其識別提供者,也不支援布建

如需前兩個案例的詳細資訊,其中應用程式支援布建或使用LDAP目錄 SQL 資料庫、具有SOAP或REST API,或依賴 Microsoft Entra ID 作為其識別提供者,請參閱管理應用程式現有使用者的文章。 本文說明如何針對這些應用程式類別的現有使用者使用身分識別控管功能。

本文涵蓋第三個案例。 對於某些舊版應用程式,從應用程式移除其他識別提供者或本機認證驗證,或啟用布建這些應用程式的通訊協定可能不可行。 針對這些應用程式,如果您想要使用 Microsoft Entra ID 來檢閱誰可以存取該應用程式,或從該應用程式移除某人的存取權,您必須在代表應用程式使用者的 Microsoft Entra ID 中建立指派。 本文涵蓋未使用 Microsoft Entra ID 做為其識別提供者且不支援布建的應用程式案例。

授權需求

使用此功能需要 Microsoft Entra ID 控管授權。 若要尋找您需求的正確授權,請參閱 Microsoft Entra ID 控管 授權基本概念

詞彙

本文說明如何使用 Microsoft Graph PowerShell Cmdlet 來管理應用程式角色指派的程式。 它會使用下列 Microsoft Graph 術語。

說明 Microsoft Graph 術語的圖表。

在 Microsoft Entra ID 中,服務主體 (ServicePrincipal) 代表特定組織目錄中的應用程式。 ServicePrincipal 具有稱為 AppRoles 的屬性,其中列出應用程式支援的角色,例如 Marketing specialistAppRoleAssignment 將使用者連結至服務主體,並指定使用者在該應用程式中擁有的角色。

您也可以使用 Microsoft Entra 權利管理 存取套件,為使用者提供應用程式限時存取權。 在權利管理中, AccessPackage 包含一或多個資源角色,可能來自多個服務主體。 AccessPackage 也有指派 (Assignment) 供使用者存取套件使用。

當您為使用者建立存取套件的指派時,Microsoft Entra 權利管理會自動為使用者為每個應用程式建立必要的 AppRoleAssignment 實例。 如需詳細資訊,請參閱 管理 Microsoft Entra 權利管理 中資源的存取權教學課程,以瞭解如何透過 PowerShell 建立存取套件。

開始之前

  • 您的租用戶中必須有下列其中一個授權:

    • Microsoft Entra ID P2 或 Microsoft Entra ID 控管
    • Enterprise Mobility + Security E5 授權
  • 您必須具備適當的系統管理角色。 如果這是您第一次執行這些步驟,您需要全域 管理員 istrator 角色,才能授權在租使用者中使用 Microsoft Graph PowerShell。

  • 您的應用程式需要租使用者中的服務主體。 如果服務主體尚未存在,您可以註冊應用程式,以在 Microsoft Entra 識別碼中代表它。

從應用程式收集現有的使用者

確保所有用戶都記錄在 Microsoft Entra ID 中的第一個步驟是收集具有應用程式存取權的現有使用者清單。

某些應用程式可能有內建命令,可從資料存放區匯出目前用戶的清單。 在其他情況下,應用程式可能會依賴外部目錄或資料庫。

在某些環境中,應用程式可能位於不適合管理 Microsoft Entra 識別符存取權的網路區段或系統上。 因此,您可能需要從該應用程式、目錄或資料庫擷取使用者清單,然後將它當作檔案傳送到另一個系統,以用於 Microsoft Entra 互動。

如果您的應用程式有LDAP目錄或SQL資料庫,請參閱 從應用程式 收集現有使用者,以取得如何擷取使用者集合的建議。

否則,如果應用程式沒有目錄或資料庫,您必須連絡應用程式的擁有者,並讓他們提供使用者清單。 這可以是 CSV 檔案等格式,每個使用者一行。 請確定檔案中每個使用者的一個字段包含唯一標識符,例如電子郵件位址,也存在於 Microsoft Entra ID 中的使用者上。

如果此系統未安裝 Microsoft Graph PowerShell Cmdlet 或未連線到 Microsoft Entra ID,請將包含使用者的 CSV 檔案傳送至 已安裝 Microsoft Graph PowerShell Cmdlet 的系統

確認 Microsoft Entra ID 具有符合應用程式用戶的使用者

既然您有從應用程式取得的所有使用者清單,您將會比對來自應用程式資料存放區的使用者與 Microsoft Entra ID 中的使用者。

在 Microsoft Entra ID 中擷取使用者的標識碼

本節說明如何使用 Microsoft Graph PowerShell Cmdlet 與 Microsoft Entra ID 互動。

第一次貴組織針對此案例使用這些 Cmdlet 時,您必須具有全域 管理員 istrator 角色,才能在租使用者中使用 Microsoft Graph PowerShell。 後續的互動可以使用較低許可權的角色,例如:

  • 如果您預期要建立新的使用者,使用者 管理員 istrator。
  • 如果您只是管理應用程式角色指派,應用程式 管理員 istrator 或 Identity Governance 管理員 istrator
  1. 開啟 PowerShell。

  2. 如果您尚未 安裝 Microsoft Graph PowerShell 模組 ,請使用此命令來安裝 Microsoft.Graph.Users 模組和其他模組:

    Install-Module Microsoft.Graph
    

    如果您已安裝模組,請確定您使用的是最新版本:

    Update-Module microsoft.graph.users,microsoft.graph.identity.governance,microsoft.graph.applications
    
  3. 連線 至 Microsoft Entra 識別碼:

    $msg = Connect-MgGraph -ContextScope Process -Scopes "User.ReadWrite.All,Application.ReadWrite.All,AppRoleAssignment.ReadWrite.All,EntitlementManagement.ReadWrite.All"
    
  4. 如果這是您第一次使用此命令,您可能需要同意允許 Microsoft Graph 命令行工具擁有這些許可權。

  5. 將從應用程式資料存放區取得的使用者清單讀取到 PowerShell 工作階段。 如果使用者在 CSV 檔案中,您可以使用 PowerShell Cmdlet Import-Csv ,並提供上一節中檔案的名稱做為自變數。

    例如,如果從 SAP Cloud Identity Services 取得的檔案名為 Users-exported-from-sap.csv 且位於目前目錄中,請輸入此命令。

    $filename = ".\Users-exported-from-sap.csv"
    $dbusers = Import-Csv -Path $filename -Encoding UTF8
    

    如需另一個範例,如果您使用資料庫或目錄,如果檔案名為 users.csv 且位於目前目錄中,請輸入下列命令:

    $filename = ".\users.csv"
    $dbusers = Import-Csv -Path $filename -Encoding UTF8
    
  6. 選擇與 Microsoft Entra ID 中使用者屬性相符之users.csv檔案的數據行。

    如果您使用 SAP 雲端識別服務,則預設對應是具有 Microsoft Entra ID 屬性的 SAP SCIM 屬性userNameuserPrincipalName

    $db_match_column_name = "userName"
    $azuread_match_attr_name = "userPrincipalName"
    

    針對另一個範例,如果您使用資料庫或目錄,則資料庫中的使用者,其中名為 EMail 的數據行值與 Microsoft Entra 屬性 userPrincipalName中的值相同:

    $db_match_column_name = "EMail"
    $azuread_match_attr_name = "userPrincipalName"
    
  7. 在 Microsoft Entra ID 中擷取這些使用者的標識碼。

    下列 PowerShell 腳本會使用 $dbusers稍早指定的、 $db_match_column_name$azuread_match_attr_name 值。 它會查詢 Microsoft Entra 識別碼,以找出具有來源檔案中每個記錄相符值的屬性的使用者。 如果檔案中有許多使用者從來源 SAP Cloud Identity Services、資料庫或目錄取得,此腳本可能需要幾分鐘的時間才能完成。 如果您的 Microsoft Entra ID 中沒有具有 值的屬性,而且需要使用 contains 或其他篩選表達式,則必須自定義下列步驟 11 中的 屬性,才能使用不同的篩選表達式。

    $dbu_not_queried_list = @()
    $dbu_not_matched_list = @()
    $dbu_match_ambiguous_list = @()
    $dbu_query_failed_list = @()
    $azuread_match_id_list = @()
    $azuread_not_enabled_list = @()
    $dbu_values = @()
    $dbu_duplicate_list = @()
    
    foreach ($dbu in $dbusers) { 
       if ($null -ne $dbu.$db_match_column_name -and $dbu.$db_match_column_name.Length -gt 0) { 
          $val = $dbu.$db_match_column_name
          $escval = $val -replace "'","''"
          if ($dbu_values -contains $escval) { $dbu_duplicate_list += $dbu; continue } else { $dbu_values += $escval }
          $filter = $azuread_match_attr_name + " eq '" + $escval + "'"
          try {
             $ul = @(Get-MgUser -Filter $filter -All -Property Id,accountEnabled -ErrorAction Stop)
             if ($ul.length -eq 0) { $dbu_not_matched_list += $dbu; } elseif ($ul.length -gt 1) {$dbu_match_ambiguous_list += $dbu } else {
                $id = $ul[0].id; 
                $azuread_match_id_list += $id;
                if ($ul[0].accountEnabled -eq $false) {$azuread_not_enabled_list += $id }
             } 
          } catch { $dbu_query_failed_list += $dbu } 
        } else { $dbu_not_queried_list += $dbu }
    }
    
    
  8. 檢視先前查詢的結果。 查看 SAP Cloud Identity Services、資料庫或目錄中是否有任何使用者因為錯誤或遺漏相符專案而無法位於 Microsoft Entra ID 中。

    下列 PowerShell 腳稿會顯示未找到的記錄計數:

    $dbu_not_queried_count = $dbu_not_queried_list.Count
    if ($dbu_not_queried_count -ne 0) {
      Write-Error "Unable to query for $dbu_not_queried_count records as rows lacked values for $db_match_column_name."
    }
    $dbu_duplicate_count = $dbu_duplicate_list.Count
    if ($dbu_duplicate_count -ne 0) {
      Write-Error "Unable to locate Microsoft Entra ID users for $dbu_duplicate_count rows as multiple rows have the same value"
    }
    $dbu_not_matched_count = $dbu_not_matched_list.Count
    if ($dbu_not_matched_count -ne 0) {
      Write-Error "Unable to locate $dbu_not_matched_count records in Microsoft Entra ID by querying for $db_match_column_name values in $azuread_match_attr_name."
    }
    $dbu_match_ambiguous_count = $dbu_match_ambiguous_list.Count
    if ($dbu_match_ambiguous_count -ne 0) {
      Write-Error "Unable to locate $dbu_match_ambiguous_count records in Microsoft Entra ID as attribute match ambiguous."
    }
    $dbu_query_failed_count = $dbu_query_failed_list.Count
    if ($dbu_query_failed_count -ne 0) {
      Write-Error "Unable to locate $dbu_query_failed_count records in Microsoft Entra ID as queries returned errors."
    }
    $azuread_not_enabled_count = $azuread_not_enabled_list.Count
    if ($azuread_not_enabled_count -ne 0) {
     Write-Error "$azuread_not_enabled_count users in Microsoft Entra ID are blocked from sign-in."
    }
    if ($dbu_not_queried_count -ne 0 -or $dbu_duplicate_count -ne 0 -or $dbu_not_matched_count -ne 0 -or $dbu_match_ambiguous_count -ne 0 -or $dbu_query_failed_count -ne 0 -or $azuread_not_enabled_count) {
     Write-Output "You will need to resolve those issues before access of all existing users can be reviewed."
    }
    $azuread_match_count = $azuread_match_id_list.Count
    Write-Output "Users corresponding to $azuread_match_count records were located in Microsoft Entra ID." 
    
  9. 當腳本完成時,如果數據源中的任何記錄不在 Microsoft Entra ID 中,就會指出錯誤。 如果應用程式資料存放區中使用者的所有記錄都可能以 Microsoft Entra ID 中的使用者身分,您必須調查哪些記錄不相符,以及原因為何。

    例如,某人的電子郵件位址和 userPrincipalName 可能已在 Microsoft Entra ID 中變更,而不會在應用程式的數據源中更新其對應的 mail 屬性。 或者,使用者可能已經離開組織,但仍位於應用程式的數據源中。 或者,應用程式數據源中可能有廠商或超級系統管理員帳戶,不會對應至 Microsoft Entra 識別碼中的任何特定人員。

  10. 如果有使用者無法位於 Microsoft Entra ID 中,或沒有作用中且無法登入,但您想要在 SAP Cloud Identity Services、資料庫或目錄中更新其存取權,或更新其屬性,您必須更新應用程式、比對規則,或更新或為其建立 Microsoft Entra 使用者。 如需要進行哪些變更的詳細資訊,請參閱 管理與 Microsoft Entra ID 中不符合使用者的應用程式中的對應和用戶帳戶。

    如果您選擇在 Microsoft Entra ID 中建立使用者的選項,您可以使用下列其中一項來大量建立使用者:

    • CSV 檔案,如在 Microsoft Entra 系統管理中心大量建立使用者中所述
    • New-MgUser Cmdlet

    請確定這些新使用者已填入 Microsoft Entra ID 所需的屬性,以便稍後將它們與應用程式中的現有使用者相符,以及 Microsoft Entra ID 所需的屬性,包括 userPrincipalNamemailNicknamedisplayName。 在 userPrincipalName 目錄中的所有使用者中,必須是唯一的。

    例如,您可能有資料庫中的使用者,其中名為 EMail 的數據行值是您想要作為 Microsoft Entra 使用者主體名稱使用的值、數據行中的值包含 Microsoft Entra ID 郵件暱稱,而數據行中的AliasFull name值則包含使用者的顯示名稱:

    $db_display_name_column_name = "Full name"
    $db_user_principal_name_column_name = "Email"
    $db_mail_nickname_column_name = "Alias"
    

    然後,您可以使用此腳本,為 SAP Cloud Identity Services、資料庫或目錄與 Microsoft Entra ID 中的使用者不相符的使用者建立 Microsoft Entra 使用者。 請注意,您可能需要修改此腳本,以新增組織所需的其他 Microsoft Entra 屬性,或 如果 $azuread_match_attr_name 不是 mailNicknameuserPrincipalName,才能提供該 Microsoft Entra 屬性。

    $dbu_missing_columns_list = @()
    $dbu_creation_failed_list = @()
    foreach ($dbu in $dbu_not_matched_list) {
       if (($null -ne $dbu.$db_display_name_column_name -and $dbu.$db_display_name_column_name.Length -gt 0) -and
           ($null -ne $dbu.$db_user_principal_name_column_name -and $dbu.$db_user_principal_name_column_name.Length -gt 0) -and
           ($null -ne $dbu.$db_mail_nickname_column_name -and $dbu.$db_mail_nickname_column_name.Length -gt 0)) {
          $params = @{
             accountEnabled = $false
             displayName = $dbu.$db_display_name_column_name
             mailNickname = $dbu.$db_mail_nickname_column_name
             userPrincipalName = $dbu.$db_user_principal_name_column_name
             passwordProfile = @{
               Password = -join (((48..90) + (96..122)) * 16 | Get-Random -Count 16 | % {[char]$_})
             }
          }
          try {
            New-MgUser -BodyParameter $params
          } catch { $dbu_creation_failed_list += $dbu; throw }
       } else {
          $dbu_missing_columns_list += $dbu
       }
    }
    
  11. 將任何遺漏的使用者新增至 Microsoft Entra ID 之後,請再次執行步驟 7 中的腳本。 然後從步驟 8 執行腳本。 檢查未報告任何錯誤。

    $dbu_not_queried_list = @()
    $dbu_not_matched_list = @()
    $dbu_match_ambiguous_list = @()
    $dbu_query_failed_list = @()
    $azuread_match_id_list = @()
    $azuread_not_enabled_list = @()
    $dbu_values = @()
    $dbu_duplicate_list = @()
    
    foreach ($dbu in $dbusers) { 
       if ($null -ne $dbu.$db_match_column_name -and $dbu.$db_match_column_name.Length -gt 0) { 
          $val = $dbu.$db_match_column_name
          $escval = $val -replace "'","''"
          if ($dbu_values -contains $escval) { $dbu_duplicate_list += $dbu; continue } else { $dbu_values += $escval }
          $filter = $azuread_match_attr_name + " eq '" + $escval + "'"
          try {
             $ul = @(Get-MgUser -Filter $filter -All -Property Id,accountEnabled -ErrorAction Stop)
             if ($ul.length -eq 0) { $dbu_not_matched_list += $dbu; } elseif ($ul.length -gt 1) {$dbu_match_ambiguous_list += $dbu } else {
                $id = $ul[0].id; 
                $azuread_match_id_list += $id;
                if ($ul[0].accountEnabled -eq $false) {$azuread_not_enabled_list += $id }
             } 
          } catch { $dbu_query_failed_list += $dbu } 
        } else { $dbu_not_queried_list += $dbu }
    }
    
    $dbu_not_queried_count = $dbu_not_queried_list.Count
    if ($dbu_not_queried_count -ne 0) {
      Write-Error "Unable to query for $dbu_not_queried_count records as rows lacked values for $db_match_column_name."
    }
    $dbu_duplicate_count = $dbu_duplicate_list.Count
    if ($dbu_duplicate_count -ne 0) {
      Write-Error "Unable to locate Microsoft Entra ID users for $dbu_duplicate_count rows as multiple rows have the same value"
    }
    $dbu_not_matched_count = $dbu_not_matched_list.Count
    if ($dbu_not_matched_count -ne 0) {
      Write-Error "Unable to locate $dbu_not_matched_count records in Microsoft Entra ID by querying for $db_match_column_name values in $azuread_match_attr_name."
    }
    $dbu_match_ambiguous_count = $dbu_match_ambiguous_list.Count
    if ($dbu_match_ambiguous_count -ne 0) {
      Write-Error "Unable to locate $dbu_match_ambiguous_count records in Microsoft Entra ID as attribute match ambiguous."
    }
    $dbu_query_failed_count = $dbu_query_failed_list.Count
    if ($dbu_query_failed_count -ne 0) {
      Write-Error "Unable to locate $dbu_query_failed_count records in Microsoft Entra ID as queries returned errors."
    }
    $azuread_not_enabled_count = $azuread_not_enabled_list.Count
    if ($azuread_not_enabled_count -ne 0) {
     Write-Warning "$azuread_not_enabled_count users in Microsoft Entra ID are blocked from sign-in."
    }
    if ($dbu_not_queried_count -ne 0 -or $dbu_duplicate_count -ne 0 -or $dbu_not_matched_count -ne 0 -or $dbu_match_ambiguous_count -ne 0 -or $dbu_query_failed_count -ne 0 -or $azuread_not_enabled_count -ne 0) {
     Write-Output "You will need to resolve those issues before access of all existing users can be reviewed."
    }
    $azuread_match_count = $azuread_match_id_list.Count
    Write-Output "Users corresponding to $azuread_match_count records were located in Microsoft Entra ID." 
    

註冊應用程式

如果應用程式已在 Microsoft Entra ID 中註冊,請繼續進行下一個步驟。

您使用的帳戶必須具有管理 Microsoft Entra 識別碼中應用程式的許可權。 下列任何 Microsoft Entra 角色都包含必要的許可權:

  1. 建立應用程式和服務主體。

    例如,如果企業應用程式命名 CORPDB1為 ,請輸入下列命令:

    $azuread_app_name = "CORPDB1"
    $azuread_app = New-MgApplication -DisplayName $azuread_app_name
    $azuread_sp = New-MgServicePrincipal -DisplayName $azuread_app_name -AppId $azuread_app.AppId
    
  2. 將角色新增至應用程式,並將應用程式標記為與 Microsoft Entra ID 整合,以便檢閱其指派。 例如,如果角色名稱為 General,請在下列 PowerShell 命令中提供該值:

    $ar0 = New-Object Microsoft.Graph.PowerShell.Models.MicrosoftGraphAppRole
    $ar0.AllowedMemberTypes += "User"
    $ar0.Description = "General role"
    $ar0.DisplayName = "General"
    $ar0.id = New-Guid
    $ar0.IsEnabled = $true
    $ar0.Value = "General"
    $ara = @()
    $ara += $ar0
    
    $azuread_app_tags = @()
    $azuread_app_tags += "WindowsAzureActiveDirectoryIntegratedApp"
    
    $azuread_app_update = Update-MgApplication -ApplicationId $azuread_app.Id -AppRoles $ara -Tags $azuread_app_tags
    

檢查尚未指派給應用程式的使用者

先前的步驟已確認應用程式數據存放區中的所有使用者都以 Microsoft Entra ID 中的使用者身分存在。 不過,它們目前可能未全部指派給 Microsoft Entra 識別碼中的應用程式角色。 因此,後續步驟是查看哪些用戶沒有應用程式角色的指派。

  1. 查閱應用程式服務主體的服務主體標識碼。

    例如,如果企業應用程式命名 CORPDB1為 ,請輸入下列命令:

    $azuread_app_name = "CORPDB1"
    $azuread_sp_filter = "displayName eq '" + ($azuread_app_name -replace "'","''") + "'"
    $azuread_sp = Get-MgServicePrincipal -Filter $azuread_sp_filter -All
    
  2. 擷取目前在 Microsoft Entra ID 中指派給應用程式的使用者。

    這會以上一個命令中設定的 $azuread_sp 變數為基礎。

    $azuread_existing_assignments = @(Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $azuread_sp.Id -All)
    
  3. 比較上一節的使用者識別碼清單與目前指派給應用程式的使用者:

    $azuread_not_in_role_list = @()
    foreach ($id in $azuread_match_id_list) {
       $found = $false
       foreach ($existing in $azuread_existing_assignments) {
          if ($existing.principalId -eq $id) {
             $found = $true; break;
          }
       }
       if ($found -eq $false) { $azuread_not_in_role_list += $id }
    }
    $azuread_not_in_role_count = $azuread_not_in_role_list.Count
    Write-Output "$azuread_not_in_role_count users in the application's data store are not assigned to the application roles."
    

    如果未將零位使用者指派給應用程式角色,表示所有使用者都指派給應用程式角色,則您不需要進行任何進一步的變更,再執行存取權檢閱。

    不過,如果目前未將一或多個使用者指派給應用程式角色,您必須繼續程式,並將其新增至其中一個應用程式的角色。

  4. 選取要指派其餘用戶的應用程式角色。

    應用程式可能有多個角色。 使用此指令來列出可用的角色:

    $azuread_sp.AppRoles | where-object {$_.AllowedMemberTypes -contains "User"} | ft DisplayName,Id
    

    從清單中選取適當的角色,並取得其角色識別符。 例如,如果角色名稱為 General,請在下列 PowerShell 命令中提供該值:

    $azuread_app_role_name = "General"
    $azuread_app_role_id = ($azuread_sp.AppRoles | where-object {$_.AllowedMemberTypes -contains "User" -and $_.DisplayName -eq $azuread_app_role_name}).Id
    if ($null -eq $azuread_app_role_id) { write-error "role $azuread_app_role_name not located in application manifest"}
    

在 Microsoft Entra ID 中建立應用程式角色指派

若要讓 Microsoft Entra 識別碼符合應用程式中的使用者與 Microsoft Entra 識別碼中的使用者,您必須在 Microsoft Entra ID 中建立應用程式角色指派。

在 Microsoft Entra ID 中為應用程式使用者建立應用程式角色指派時,且應用程式不支援布建,然後

  • 除非使用者在 Microsoft Entra ID 之外更新,或直到移除 Microsoft Entra ID 中的指派為止,否則用戶會無限期地保留在應用程式中。
  • 在下一次檢閱該應用程式的角色指派時,使用者將會包含在檢閱中。
  • 如果使用者在存取權檢閱中遭到拒絕,將會移除其應用程式角色指派。
  1. 為目前沒有角色指派的使用者建立應用程式角色指派:

    foreach ($u in $azuread_not_in_role_list) {
       $res = New-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $azuread_sp.Id -AppRoleId $azuread_app_role_id -PrincipalId $u -ResourceId $azuread_sp.Id 
    }
    
  2. 等候一分鐘,變更在 Microsoft Entra ID 內傳播。

  3. 查詢 Microsoft Entra ID 以取得更新的角色指派清單:

    $azuread_existing_assignments = @(Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $azuread_sp.Id -All)
    
  4. 將上一節的使用者識別碼清單與現在指派給應用程式的使用者比較:

    $azuread_still_not_in_role_list = @()
    foreach ($id in $azuread_match_id_list) {
       $found = $false
       foreach ($existing in $azuread_existing_assignments) {
          if ($existing.principalId -eq $id) {
             $found = $true; break;
          }
       }
       if ($found -eq $false) { $azuread_still_not_in_role_list += $id }
    }
    $azuread_still_not_in_role_count = $azuread_still_not_in_role_list.Count
    if ($azuread_still_not_in_role_count -gt 0) {
       Write-Output "$azuread_still_not_in_role_count users in the application's data store are not assigned to the application roles."
    }
    

    如果未將任何使用者指派給應用程式角色,請檢查 Microsoft Entra 稽核記錄,以取得上一個步驟的錯誤。

選取適當的檢閱者

當您建立每個存取權檢閱時,系統管理員可以選擇一或多個檢閱者。 檢閱者可以選擇用戶繼續存取資源或移除資源,以執行檢閱。

資源擁有者通常會負責執行檢閱。 如果您要建立群組的檢閱,作為檢閱模式 B 中整合之應用程式的存取權的一部分,您可以選取群組擁有者作為檢閱者。 由於 Microsoft Entra 識別碼中的應用程式不一定有擁有者,因此無法選取應用程式擁有者作為檢閱者的選項。 相反地,建立檢閱時,您可以提供應用程式擁有者的名稱做為檢閱者。

您也可以在建立群組或應用程式的檢閱時選擇多 階段檢閱。 例如,您可以選取讓每個獲指派使用者的管理員執行檢閱的第一個階段,以及資源擁有者第二個階段。 如此一來,資源擁有者就可以專注於已由其管理員核准的使用者。

建立檢閱之前,請先確認您的租使用者中有足夠的 Microsoft Entra ID P2 或 Microsoft Entra ID 控管 SKU 基座。 此外,請確認所有檢閱者都是具有電子郵件位址的作用中使用者。 存取權檢閱開始時,他們都會檢閱來自 Microsoft Entra ID 的電子郵件。 如果檢閱者沒有信箱,當檢閱開始時或電子郵件提醒時,他們將不會收到電子郵件。 而且,如果封鎖他們無法登入 Microsoft Entra ID,他們將無法執行檢閱。

建立應用程式角色指派的檢閱

一旦用戶位於應用程式角色中,且您已識別檢閱者,您就可以設定 Microsoft Entra ID 來 開始檢閱

依照指南中的 指示來建立群組或應用程式的存取權檢閱,以建立應用程式的角色指派檢閱。 設定檢閱以在完成時套用結果。

擷取檢閱完成時更新的指派

  1. 檢閱完成時,您可以擷取具有應用程式角色指派的使用者更新清單。

    $res = (Get-MgServicePrincipalAppRoleAssignedTo -ServicePrincipalId $azuread_sp.Id -All)
    
  2. 數據行 PrincipalDisplayName ,並 PrincipalId 包含保留應用程式角色指派之每個用戶的顯示名稱和 Microsoft Entra 使用者識別碼。

設定權利管理與 ServiceNow 進行票證整合 (選擇性)

如果您有 ServiceNow,您可以選擇性地設定自動化 ServiceNow 票證建立,並透過 Logic Apps 使用 權利管理整合 。 在該案例中,權利管理可以自動建立 ServiceNow 票證,以手動布建已接收存取套件指派的使用者。

下一步