共用方式為


將群組從一個樹系移轉至另一個樹系,以供 Microsoft Entra 連線

本文說明如何將群組從一個樹系移轉至另一個樹系,讓移轉的群組物件符合雲端中的現有物件。

必要條件

  • Microsoft Entra 連線 1.5.18.0 版或更新版本
  • 來源錨點屬性設定為 mS-DS-ConsistencyGuid

遷移群組

從 1.5.18.0 版開始,Microsoft Entra 連線支援對群組使用 mS-DS-ConsistencyGuid 屬性。 如果您選擇 mS-DS-ConsistencyGuid 作為來源錨點屬性,並在 Active Directory 中填入值,Microsoft Entra 連線會使用 的值 mS-DS-ConsistencyGuid 作為 immutableId 。 否則,它會回復為使用 objectGUID 。 但請注意,Microsoft Entra 連線不會將值寫回 mS-DS-ConsistencyGuid Active Directory 中的 屬性。

在跨樹系移動期間,當群組物件從一個樹系移動(例如 F1)移到另一個樹系時(例如 F2),您需要將值(如果有的話)或 objectGUID 從樹系 F1 mS-DS-ConsistencyGuid 中的物件的值複製到 mS-DS-ConsistencyGuid F2 中的 物件屬性。

使用下列腳本作為指南,瞭解如何將單一群組從一個樹系移轉至另一個樹系。 您也可以使用這些腳本作為移轉多個群組的指南。 腳本會針對來源樹系使用樹系名稱 F1,而目的地樹系則使用 F2。

首先,我們會取得 objectGUID 樹系 F1 中的 和 mS-DS-ConsistencyGuid 群組物件。 這些屬性會匯出至 CSV 檔案。

<#
DESCRIPTION
============
This script will take DN of a group as input.
It then copies the objectGUID and mS-DS-ConsistencyGuid values along with other attributes of the given group to a CSV file.

This CSV file can then be used as input to the Export-Group script.
#>
Param(
       [ValidateNotNullOrEmpty()]
       [string]
       $dn,

       [ValidateNotNullOrEmpty()]
       [string]
       $outputCsv
)

$defaultProperties = @('samAccountName', 'distinguishedName', 'objectGUID', 'mS-DS-ConsistencyGuid')
$group  = Get-ADGroup -Filter "DistinguishedName -eq '$dn'" -Properties $defaultProperties -ErrorAction Stop
$results = @()
if ($group -eq $null)
{
       Write-Error "Group not found"
}
else
{
       $objectGUIDValue = [GUID]$group.'objectGUID'
       $mSDSConsistencyGuidValue = "N/A"
       if ($group.'mS-DS-ConsistencyGuid' -ne $null)
       {
              $mSDSConsistencyGuidValue = [GUID]$group.'mS-DS-ConsistencyGuid'
       }
       $adgroup = New-Object -TypeName PSObject
       $adgroup | Add-Member -MemberType NoteProperty -Name samAccountName -Value $($group.'samAccountName')
       $adgroup | Add-Member -MemberType NoteProperty -Name distinguishedName -Value $($group.'distinguishedName')
       $adgroup | Add-Member -MemberType NoteProperty -Name objectGUID -Value $($objectGUIDValue)
       $adgroup | Add-Member -MemberType NoteProperty -Name mS-DS-ConsistencyGuid -Value $($mSDSConsistencyGuidValue)
       $results += $adgroup
}

Write-Host "Exporting group to output file"
$results | Export-Csv "$outputCsv" -NoTypeInformation

接下來,我們會使用產生的輸出 CSV 檔案來戳記 mS-DS-ConsistencyGuid 樹系 F2 中目標物件上的 屬性:

<#
DESCRIPTION
============
This script will take DN of a group as input and the CSV file that was generated by the Import-Group script.
It copies either the objectGUID or the mS-DS-ConsistencyGuid value from the CSV file to the given object.

#>
Param(
       [ValidateNotNullOrEmpty()]
       [string]
       $dn,

       [ValidateNotNullOrEmpty()]
       [string]
       $inputCsv
)

$group  = Get-ADGroup -Filter "DistinguishedName -eq '$dn'" -ErrorAction Stop
if ($group -eq $null)
{
       Write-Error "Group not found"
}

$csvFile = Import-Csv -Path $inputCsv -ErrorAction Stop
$msDSConsistencyGuid = $csvFile.'mS-DS-ConsistencyGuid'
$objectGuid = [GUID] $csvFile.'objectGUID'
$targetGuid = $msDSConsistencyGuid

if ($msDSConsistencyGuid -eq "N/A")
{
       $targetGuid = $objectGuid
}

Set-ADGroup -Identity $dn -Replace @{'mS-DS-ConsistencyGuid'=$targetGuid} -ErrorAction Stop

下一步

深入瞭解 整合內部部署身分識別與 Microsoft Entra ID