將靜態群組成員資格變更為 Microsoft Entra ID 中的動態

您可以在 Microsoft Entra 識別符中,將群組的成員資格從靜態變更為動態(反之亦然)。 Microsoft Entra ID 會在系統中保留相同的組名和標識符,因此群組的所有現有參考仍然有效。 如果您改為建立新的群組,則必須更新這些參考。 動態群組成員資格可避免管理額外負荷新增和移除使用者。 本文說明如何使用入口網站或PowerShell Cmdlet,將現有的群組從靜態轉換成動態成員資格。

警告

將現有的靜態群組變更為動態群組時,所有現有的成員都會從群組中移除,然後處理成員資格規則以新增成員。 如果群組用來控制對應用程式或資源的存取,請注意原始成員可能會失去存取權,直到完整處理成員資格規則為止。

建議您事先測試新的成員資格規則,以確保群組中的新成員資格如預期般。

變更群組的成員資格類型

您可以使用已指派全域管理員、使用者管理員或群組系統管理員角色的帳戶來執行下列步驟。

  1. 以至少群組 管理員 istrator 身分登入 Microsoft Entra 系統管理中心
  2. 選取 [Microsoft Entra ID]。
  3. 群組
  4. 從 [ 所有群組] 列表中,開啟您想要變更的群組。
  5. 選取屬性
  6. 在群組的 [屬性] 頁面上,根據您所需的成員資格類型,選取 [已指派][靜態]、[動態使用者] 或 [動態裝置] 的成員資格類型。 針對動態成員資格,您可以使用規則產生器來選取簡單規則的選項,或自行撰寫成員資格規則。

下列步驟是將群組從靜態變更為使用者群組動態成員資格的範例。

  1. 在所選群組的 [屬性] 頁面上,選取動態使用者的成員資格類型,然後在對話框中選取 [是],說明群組成員資格的變更以繼續。

    Screenshot of selecting membership type of dynamic user.

  2. 選取 [ 新增動態查詢],然後提供規則。

    Screenshot of entering the rule for the dynamic group.

  3. 建立規則之後,請選取 頁面底部的 [新增查詢 ]。

  4. 在群組的 [屬性] 頁面上選取 [儲存],以儲存變更。 群組 的成員資格類型 會在群組清單中立即更新。

提示

如果您輸入的成員資格規則不正確,群組轉換可能會失敗。 入口網站右上角會顯示通知,其中包含系統無法接受規則的原因說明。 請仔細閱讀,以瞭解如何調整規則使其有效。 如需規則語法和成員資格規則支援屬性、運算符和值的完整清單範例,請參閱 Microsoft Entra ID 中群組的動態成員資格規則。

變更群組的成員資格類型 (PowerShell)

注意

若要變更動態群組屬性,您必須從 Microsoft Graph PowerShell 模組使用 Cmdlet。 如需詳細資訊,請參閱 安裝 Microsoft Graph PowerShell SDK

以下是在現有群組上切換成員資格管理的函式範例。 在此範例中,請小心正確地操作 GroupTypes 屬性,並保留與動態成員資格無關的任何值。

#The moniker for dynamic groups as used in the GroupTypes property of a group object
$dynamicGroupTypeString = "DynamicMembership"

function ConvertDynamicGroupToStatic
{
    Param([string]$groupId)

    #existing group types
    [System.Collections.ArrayList]$groupTypes = (Get-MgGroup -GroupId $groupId).GroupTypes

    if($groupTypes -eq $null -or !$groupTypes.Contains($dynamicGroupTypeString))
    {
        throw "This group is already a static group. Aborting conversion.";
    }


    #remove the type for dynamic groups, but keep the other type values
    $groupTypes.Remove($dynamicGroupTypeString)

    #modify the group properties to make it a static group: i) change GroupTypes to remove the dynamic type, ii) pause execution of the current rule
    Update-MgGroup -GroupId $groupId -GroupTypes $groupTypes.ToArray() -MembershipRuleProcessingState "Paused"
}

function ConvertStaticGroupToDynamic
{
    Param([string]$groupId, [string]$dynamicMembershipRule)

    #existing group types
    [System.Collections.ArrayList]$groupTypes = (Get-MgGroup -GroupId $groupId).GroupTypes

    if($groupTypes -ne $null -and $groupTypes.Contains($dynamicGroupTypeString))
    {
        throw "This group is already a dynamic group. Aborting conversion.";
    }
    #add the dynamic group type to existing types
    $groupTypes.Add($dynamicGroupTypeString)

    #modify the group properties to make it a static group: i) change GroupTypes to add the dynamic type, ii) start execution of the rule, iii) set the rule
    Update-MgGroup -GroupId $groupId -GroupTypes $groupTypes.ToArray() -MembershipRuleProcessingState "On" -MembershipRule $dynamicMembershipRule
}

若要讓群組成為靜態:

ConvertDynamicGroupToStatic "a58913b2-eee4-44f9-beb2-e381c375058f"

若要讓群組成為動態:

ConvertStaticGroupToDynamic "a58913b2-eee4-44f9-beb2-e381c375058f" "user.displayName -startsWith ""Peter"""

下一步

這些文章提供 Microsoft Entra ID 中群組的其他資訊。