可以在 Microsoft Entra ID 中将组的成员身份从静态更改为动态(反之亦然)。 Microsoft Entra ID 在系统中保留相同的组名和 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"""