修改 Microsoft Entra Connect 组写回默认行为

借助组写回功能,可以使用 Microsoft Entra Connect Sync 将云组写回到本地 Active Directory 实例。可以通过以下方式更改默认行为:

  • 只有配置了写回的组才会写回,包括新建的 Microsoft 365 组。
  • 如果已写回的组在 Azure AD 中禁用组写回、被软删除或硬删除,将在 Microsoft Entra ID 中删除这些组。
  • 可以将包含至多 250,000 个成员的 Microsoft 365 组写回本地。

本文将引导你了解用于修改 Microsoft Entra Connect 组写回的默认行为的选项。

现有部署的注意事项

如果已在环境中启用并且正在使用组写回的原始版本,则所有 Microsoft 365 组都已写回到 Active Directory。 可以不禁用所有 Microsoft 365 组,而是查看以前写回的组的用法。 仅禁用在本地 Active Directory 中不再需要的那些组。

禁用新的 Microsoft 365 组的自动写回

若要配置目录设置以禁用新创建的 Microsoft 365 组的自动写回,请使用以下方法之一:

  • PowerShell:使用 Microsoft Graph Beta PowerShell SDK。 例如:

      # Import Module
      Import-Module Microsoft.Graph.Beta.Identity.DirectoryManagement
    
      #Connect to MgGraph with necessary scope
      Connect-MgGraph -Environment China -Scopes Directory.ReadWrite.All
    
    
      # Verify if "Group.Unified" directory settings exist
      $DirectorySetting = Get-MgBetaDirectorySetting| Where-Object {$_.DisplayName -eq "Group.Unified"}
    
      # If "Group.Unified" directory settings exist, update the value for new unified group writeback default
      if ($DirectorySetting) 
      {
        $params = @{
          Values = @(
            @{
              Name = "NewUnifiedGroupWritebackDefault"
              Value = $false
            }
          )
        }
        Update-MgBetaDirectorySetting -DirectorySettingId $DirectorySetting.Id -BodyParameter $params
      }
      else
      {
        # In case the directory setting doesn't exist, create a new "Group.Unified" directory setting
        # Import "Group.Unified" template values to a hashtable
        $Template = Get-MgBetaDirectorySettingTemplate | Where-Object {$_.DisplayName -eq "Group.Unified"}
        $TemplateValues = @{}
        $Template.Values | ForEach-Object {
            $TemplateValues.Add($_.Name, $_.DefaultValue)
        }
    
        # Update the value for new unified group writeback default
        $TemplateValues["NewUnifiedGroupWritebackDefault"] = $false
    
        # Create a directory setting using the Template values hashtable including the updated value
        $params = @{}
        $params.Add("TemplateId", $Template.Id)
        $params.Add("Values", @())
        $TemplateValues.Keys | ForEach-Object {
            $params.Values += @(@{Name = $_; Value = $TemplateValues[$_]})
        }
        New-MgBetaDirectorySetting -BodyParameter $params
      }
    

注意

建议将 Microsoft Graph PowerShell SDK 与 PowerShell 7 配合使用。

为所有现有的 Microsoft 365 组禁用写回

若要禁用在进行这些修改之前创建的所有 Microsoft 365 组的写回,请使用以下方法之一:

  • 门户:使用 Microsoft Entra 管理中心

  • PowerShell:使用 Microsoft Graph Beta PowerShell SDK。 例如:

      #Import-module
      Import-Module Microsoft.Graph.Beta
    
      #Connect to MgGraph with necessary scope
      Connect-MgGraph -Environment China -Scopes Group.ReadWrite.All
    
      #List all Microsoft 365 Groups
      $Groups = Get-MgBetaGroup -All | Where-Object {$_.GroupTypes -like "*unified*"}
    
      #Disable Microsoft 365 Groups
      Foreach ($group in $Groups) 
      {
        Update-MgBetaGroup -GroupId $group.id -WritebackConfiguration @{isEnabled=$false}
      }
    

在组禁用写回或被软删除时,删除这些组

注意

在 Active Directory 中删除已写回组后,如果这些组重新启用写回或从软删除状态还原,则无法借助 Active Directory 回收站功能自动将其还原。 将创建新组。 在重新启用写回之前从 Active Directory 回收站还原的已删除组,或从 Microsoft Entra ID 中的软删除状态还原的已删除组,将加入其各自的 Microsoft Entra 组。

  1. 在 Microsoft Entra Connect 服务器上,以管理员身份打开 PowerShell 提示。

  2. 禁用 Microsoft Entra Connect 同步计划程序

    Set-ADSyncScheduler -SyncCycleEnabled $false  
    
  3. 在 Microsoft Entra Connect 中创建自定义同步规则,以便在已写回的组禁用写回或被软删除时,删除这些组:

    import-module ADSync 
    $precedenceValue = Read-Host -Prompt "Enter a unique sync rule precedence value [0-99]" 
    
    New-ADSyncRule  `
    -Name 'In from AAD - Group SOAinAAD Delete WriteBackOutOfScope and SoftDelete' `
    -Identifier 'cb871f2d-0f01-4c32-a333-ff809145b947' `
    -Description 'Delete AD groups that fall out of scope of Group Writeback or get Soft Deleted in Azure AD' `
    -Direction 'Inbound' `
    -Precedence $precedenceValue `
    -PrecedenceAfter '00000000-0000-0000-0000-000000000000' `
    -PrecedenceBefore '00000000-0000-0000-0000-000000000000' `
    -SourceObjectType 'group' `
    -TargetObjectType 'group' `
    -Connector 'b891884f-051e-4a83-95af-2544101c9083' `
    -LinkType 'Join' `
    -SoftDeleteExpiryInterval 0 `
    -ImmutableTag '' `
    -OutVariable syncRule
    
    Add-ADSyncAttributeFlowMapping  `
    -SynchronizationRule $syncRule[0] `
    -Destination 'reasonFiltered' `
    -FlowType 'Expression' `
    -ValueMergeType 'Update' `
    -Expression 'IIF((IsPresent([reasonFiltered]) = True) && (InStr([reasonFiltered], "WriteBackOutOfScope") > 0 || InStr([reasonFiltered], "SoftDelete") > 0), "DeleteThisGroupInAD", [reasonFiltered])' `
     -OutVariable syncRule
    
    New-Object  `
    -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.ScopeCondition' `
    -ArgumentList 'cloudMastered','true','EQUAL' `
    -OutVariable condition0
    
    Add-ADSyncScopeConditionGroup  `
    -SynchronizationRule $syncRule[0] `
    -ScopeConditions @($condition0[0]) `
    -OutVariable syncRule
    
    New-Object  `
    -TypeName 'Microsoft.IdentityManagement.PowerShell.ObjectModel.JoinCondition' `
    -ArgumentList 'cloudAnchor','cloudAnchor',$false `
    -OutVariable condition0
    
    Add-ADSyncJoinConditionGroup  `
    -SynchronizationRule $syncRule[0] `
    -JoinConditions @($condition0[0]) `
    -OutVariable syncRule
    
    Add-ADSyncRule  `
    -SynchronizationRule $syncRule[0]
    
    Get-ADSyncRule  `
    -Identifier 'cb871f2d-0f01-4c32-a333-ff809145b947'
    
  4. 启用组写回

  5. 启用 Microsoft Entra Connect 同步计划程序:

    Set-ADSyncScheduler -SyncCycleEnabled $true  
    

注意

创建同步规则将在 Microsoft Entra 连接器上将完全同步标志设置为 true。 此更改将导致规则更改在下一个同步周期中传播。

写回包含至多 250,000 个成员的 Microsoft 365 组

由于限制组大小的默认同步规则是在启用组写回时创建的,因此在启用组写回后必须完成以下步骤:

  1. 在 Microsoft Entra Connect 服务器上,以管理员身份打开 PowerShell 提示。

  2. 禁用 Microsoft Entra Connect 同步计划程序

    Set-ADSyncScheduler -SyncCycleEnabled $false  
    
  3. 打开同步规则编辑器

  4. 将方向设置为“出站”。

  5. 查找并禁用“传出到 AD - 组写回成员限制”同步规则。

  6. 启用 Microsoft Entra Connect 同步计划程序:

    Set-ADSyncScheduler -SyncCycleEnabled $true  
    

注意

禁用同步规则将在 Microsoft Entra 连接器上将完全同步标志设置为 true。 此更改将导致规则更改在下一个同步周期中传播。

从 Active Directory 回收站还原

如果要更新默认行为,以便在组禁用写回或被软删除时删除这些组,建议为 Active Directory 的本地实例启用 Active Directory 回收站功能。 可以使用此功能手动还原以前删除的 Active Directory 组,以便它们可以重新加入其各自的 Microsoft Entra 组(如果这些组以外禁用了写回或被软删除)。

在 Microsoft Entra ID 中重新启用写回或从软删除还原之前,首先需要在 Active Directory 中还原组。

后续步骤