您可以在 Microsoft Entra 識別符中,將群組的成員資格從靜態變更為動態(反之亦然)。 Microsoft Entra ID 會在系統中保留相同的群組名稱和識別碼,因此群組的所有現有參考仍然有效。 如果您改為建立新的群組,則需要更新這些參考。
建立動態成員資格群組可消除新增和移除使用者的管理額外負荷。 本文說明如何使用 Azure 入口網站或 PowerShell Cmdlet,將現有的成員資格群組從靜態轉換成動態。 在 Microsoft Entra 中,單一租用戶最多可以有 15,000 個動態成員群組。
備註
當靜態群組轉換成動態成員資格群組時,符合成員資格規則的現有成員會維持不變。 未符合條件的成員會被移除。 其他滿足成員資格規則的用戶會自動新增。 如果群組用來控制對應用程式或資源的存取,原始成員可能會失去存取權,直到完整處理成員資格規則為止。
建議您先測試新的成員資格規則,以確保群組中的新成員資格如預期般運作。 如果您在測試期間遇到錯誤,請參閱 解決群組授權問題。
先決條件
若要使用入口網站變更成員資格類型,您需要至少具有 群組管理員 角色的帳戶。
若要使用PowerShell變更動態群組屬性,您需要使用來自 Microsoft Graph PowerShell 模組的 Cmdlet。 如需詳細資訊,請參閱 安裝 Microsoft Graph PowerShell SDK。
變更群組的成員資格類型 (入口網站)
以至少群組管理員身分登入 Microsoft Entra 系統管理中心 。
選取 Microsoft Entra ID。
選取群組。
在 [ 所有群組] 列表中,開啟您想要變更的群組。
選取屬性。
在群組的 屬性 頁面上,根據您想要的成員資格類型,選取 成員資格類型 值為 [已指派 (靜態)]、[動態使用者] 或 [動態裝置]。 針對組動態成員資格群組,您可以使用規則建立器來選取簡易規則的選項,或自行寫入成員資格規則。
下列步驟是將使用者群組從靜態變更為動態成員資格群組的範例:
針對 [成員資格類型],選取 [動態使用者]。 在說明動態成員資格群組變更的對話框中,選取 [ 是 ] 繼續。
選取 [新增動態查詢],然後提供規則。
建立規則之後,請選取 [新增查詢]。
在群組的 [ 屬性] 頁面上,選取 [ 儲存 ] 以儲存變更。 群組的 [成員資格類型] 會立即在群組清單中更新。
提示
如果您輸入的成員資格規則不正確,群組轉換可能會失敗。 在入口網站的右上角,通知會說明無法接受規則的原因。 請仔細閱讀,以了解您可以如何調整規則來讓規則變成有效。 有關規則語法的範例以及成員資格規則支援的屬性、運算子和值的完整列表,請參閱 Microsoft Entra ID 中的管理組動態成員資格群組規則。
變更群組的成員資格類型 (PowerShell)
以下是在現有群組上切換成員資格管理的函式範例。 這個範例正確地操作GroupTypes屬性,以保留與動態成員資格群組無關的任何值。
#The moniker for dynamic membership 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 membership groups, but keep the other type values
$groupTypes.Remove($dynamicGroupTypeString)
#Modify the group properties to make it a static group: change GroupTypes to remove the dynamic type, and then 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: change GroupTypes to add the dynamic type, start execution of the rule, and then 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"""