MS-102 GĐ5
Module 37
Manage Synced Identities
Quản lý Users, Groups được sync từ AD: soft/hard match, object filtering, writeback, xử lý duplicate, và tổng quan Microsoft Identity Manager (MIM).
Tình huống – VinaCorp
VinaCorp vừa hoàn tất sync 3.500 user từ AD. IT nhận được báo cáo: 45 user bị lỗi duplicate proxyAddresses, 12 user cloud đã tồn tại trước khi deploy Entra Connect (cần soft-match), 2 security group không xuất hiện trong Entra ID dù đã sync. IT cần audit và fix tất cả trong ngày.
Synced vs Cloud-only Identity
| Thuộc tính | Synced (on-prem) | Cloud-only |
|---|---|---|
| Nguồn gốc | AD DS → Entra Connect | Tạo trực tiếp trên Entra ID |
| Sửa thuộc tính | Sửa trên AD → auto sync | Sửa trực tiếp trên Entra Admin |
| onPremisesSyncEnabled | true | null / false |
| ImmutableId | Base64(ObjectGUID) | null |
| Password reset | SSPR + Password Writeback cần thiết | SSPR trực tiếp |
| Xóa object | Xóa trên AD → sync xóa cloud | Xóa trực tiếp cloud |
| UPN | Phải match verified domain | Bất kỳ verified domain |
Soft Match vs Hard Match
| Loại | Cách hoạt động | Khi nào dùng |
|---|---|---|
| Soft Match | Entra Connect so sánh UPN hoặc ProxyAddresses để ghép cloud user ↔ on-prem user tự động | Sau migration: cloud user đã tạo trước khi deploy Entra Connect |
| Hard Match | Gán ImmutableId thủ công = Base64(AD ObjectGUID) cho cloud user | Soft match thất bại (UPN/email khác nhau); hoặc sau restore từ backup |
Lab A – Audit Synced Users & Lỗi
Chạy trên máy có Microsoft Graph PowerShell
Xem tất cả synced users
Connect-MgGraph -Scopes "User.Read.All","Directory.Read.All"
# Đếm synced vs cloud-only
$all = Get-MgUser -All
$synced = ($all | Where-Object {$_.OnPremisesSyncEnabled -eq $true}).Count
$cloudOnly= ($all | Where-Object {$_.OnPremisesSyncEnabled -ne $true}).Count
Write-Host "Synced: $synced | Cloud-only: $cloudOnly"
Synced: 3487 | Cloud-only: 63
Xem users có lỗi provisioning
# Lấy danh sách user có lỗi sync
$errors = Get-MgUser -All -Filter "onPremisesProvisioningErrors/any(e:e/category ne '')" |
Select-Object DisplayName, UserPrincipalName,
@{N='ErrorType'; E={$_.OnPremisesProvisioningErrors[0].Category}},
@{N='ErrorValue';E={$_.OnPremisesProvisioningErrors[0].Value}}
$errors | Export-Csv "sync-errors.csv" -NoTypeInformation
$errors | Format-Table -AutoSize
DisplayName UserPrincipalName ErrorType ErrorValue
----------- ----------------- --------- ----------
Nguyen Thi Lan [email protected] AttributeValueMustBeUnique smtp:[email protected]
Le Minh Tuan [email protected] AttributeValueMustBeUnique smtp:[email protected]
... (45 rows)
Fix duplicate ProxyAddresses bằng AD PowerShell
# Chạy trên Domain Controller / máy có RSAT
Import-Module ActiveDirectory
# Tìm user có proxyAddresses trùng
$targetEmail = "smtp:[email protected]"
$dupes = Get-ADUser -Filter * -Properties proxyAddresses |
Where-Object { $_.proxyAddresses -contains $targetEmail }
$dupes | ForEach-Object {
Write-Host "User: $($_.SamAccountName) - $($_.proxyAddresses)"
}
# Xóa alias trùng khỏi user phụ (giữ lại user chính)
$secondary = Get-ADUser -Identity "lan.nt2" -Properties proxyAddresses
$newProxy = $secondary.proxyAddresses | Where-Object { $_ -ne $targetEmail }
Set-ADUser -Identity $secondary -Replace @{proxyAddresses = $newProxy}
Write-Host "Removed duplicate proxyAddress from $($secondary.SamAccountName)"
User: lan.nt - {smtp:[email protected], SMTP:[email protected]}
User: lan.nt2 - {smtp:[email protected]}
Removed duplicate proxyAddress from lan.nt2
Lab B – Soft Match & Hard Match
Soft Match tự động (kiểm tra điều kiện)
# Điều kiện soft match: UPN hoặc ProxyAddresses phải trùng
# Xem cloud user cần match
$cloudUser = Get-MgUser -UserId "[email protected]" |
Select-Object DisplayName, UserPrincipalName, OnPremisesImmutableId, OnPremisesSyncEnabled
$cloudUser
DisplayName : Vo Minh (Admin)
UserPrincipalName : [email protected]
OnPremisesImmutableId : ← chưa match
OnPremisesSyncEnabled : False
# Trên AD: đảm bảo AD user có UPN = [email protected]
Set-ADUser -Identity "vo.minh.admin" -UserPrincipalName "[email protected]"
# Sau delta sync, Entra Connect sẽ auto soft-match → ImmutableId được gán
Start-ADSyncSyncCycle -PolicyType Delta
# Sau sync, kiểm tra lại:
OnPremisesImmutableId : mX7kYp2QAE3z/d9S5iMnNQ== ← đã match!
Hard Match thủ công
# Khi soft match không khả dụng (UPN khác nhau)
# Lấy ObjectGUID từ AD
$adUser = Get-ADUser -Identity "tran.van.hoa" -Properties ObjectGUID
$immutableId = [Convert]::ToBase64String($adUser.ObjectGUID.ToByteArray())
Write-Host "ImmutableId: $immutableId"
# Gán cho cloud user tương ứng
Update-MgUser -UserId "[email protected]" -OnPremisesImmutableId $immutableId
Write-Host "Hard match applied"
# Trigger sync để hoàn tất
Start-ADSyncSyncCycle -PolicyType Delta
ImmutableId: tX3pYk1QAE2z/c8R4hLmNQ==
Hard match applied
Group Sync & Writeback
Loại Group được sync
| Loại Group (AD) | Sync lên Entra | Ghi chú |
|---|---|---|
| Security Group (Global/Universal) | ✅ Mặc định | Dùng cho Conditional Access, Intune |
| Distribution Group | ✅ Mặc định | Exchange mail-enabled |
| Domain Local Group | ❌ Mặc định không sync | Cần bật trong Sync Rules Editor |
| Entra Security Group | → Writeback về AD (P1) | Group Writeback v2 |
| Microsoft 365 Group | → Writeback về AD (P1) | Tạo Universal Distribution Group trên AD |
Bật Group Writeback v2
1Entra Admin Center → Hybrid management → Microsoft Entra Connect → Sync → Manage sync
2Chọn Group Writeback → Enable → Chọn target OU trên AD để ghi group về
3Chọn group Entra muốn writeback → Assign writeback DN
# PowerShell: bật Group Writeback cho group cụ thể
$groupId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
# Cập nhật writeback config
$params = @{
WritebackConfiguration = @{
IsEnabled = $true
OnPremisesGroupType = "universalDistributionGroup"
}
}
Update-MgGroup -GroupId $groupId -BodyParameter $params
Write-Host "Group writeback enabled"
Tại sao group không xuất hiện trong Entra (debug)
# Kiểm tra group có trong scope OU filter không
Get-ADGroup -Identity "IT_Security_VN" -Properties DistinguishedName |
Select-Object Name, DistinguishedName
# Kết quả:
# DistinguishedName: CN=IT_Security_VN,OU=Contractors,DC=vinacorp,DC=vn
# → OU=Contractors bị loại khỏi filter → Group không được sync!
# Fix: thêm OU=Contractors vào sync scope HOẶC move group sang OU được sync
Move-ADObject -Identity "CN=IT_Security_VN,OU=Contractors,DC=vinacorp,DC=vn" `
-TargetPath "OU=Corp_Groups,DC=vinacorp,DC=vn"
# Trigger delta sync
Start-ADSyncSyncCycle -PolicyType Delta
Group "IT_Security_VN" moved to Corp_Groups OU.
Delta sync started. Group will appear in Entra ID within 30 minutes.
Object Filtering nâng cao
Lọc theo Attribute (extensionAttribute)
Khi không muốn lọc theo OU mà lọc theo thuộc tính — ví dụ: chỉ sync những user có extensionAttribute1 = "SyncToCloud".
1Mở Synchronization Rules Editor (trên Entra Connect server)
2Add new Inbound rule → Connector: AD DS connector → Object type: user
3Scoping filter: extensionAttribute1 EQUAL SyncToCloud
4Action: joinNoFlow → Save → Chạy Full Sync
# Trên AD: gán attribute cho user cần sync
Get-ADUser -Filter {Department -eq "IT"} | ForEach-Object {
Set-ADUser -Identity $_ -Replace @{extensionAttribute1 = "SyncToCloud"}
}
Write-Host "Tagged IT department for cloud sync"
Tagged IT department for cloud sync
Khi user bị bỏ tag
extensionAttribute1, họ sẽ bị xóa khỏi Entra ID (soft-delete 30 ngày) ở sync cycle tiếp theo. Đảm bảo có quy trình offboarding rõ ràng.Lab C – Lifecycle: Disable, Delete, Restore
Disable user trên AD → tự động reflect lên Entra
# Disable user trên AD
Disable-ADAccount -Identity "lan.nt"
# Sau delta sync (~30 phút), user trên Entra sẽ:
# AccountEnabled: false (không thể đăng nhập M365)
# onPremisesSyncEnabled: true (vẫn là synced object)
# Kiểm tra trên Entra sau sync
Get-MgUser -UserId "[email protected]" | Select AccountEnabled, OnPremisesSyncEnabled
# AccountEnabled : False
# OnPremisesSyncEnabled: True
Xóa user an toàn (on-prem → cloud)
# Bước 1: Revoke sessions trước khi xóa
Revoke-MgUserSignInSession -UserId "[email protected]"
# Bước 2: Xóa trên AD
Remove-ADUser -Identity "lan.nt" -Confirm:$false
# Sau delta sync: user bị move vào Entra Deleted Users (soft-delete 30 ngày)
# Bước 3: Xác nhận soft-delete
Get-MgDirectoryDeletedItemAsUser -All | Where-Object {$_.UserPrincipalName -like "lan.nt*"}
Id : aaa-bbb-ccc
DisplayName : Nguyen Thi Lan
UserPrincipalName : [email protected]
DeletedDateTime : 4/20/2026 08:15:00
Restore soft-deleted user
# Restore về AD trước, sau đó restore cloud
# Bước 1: Restore AD user từ AD Recycle Bin
Restore-ADObject -Identity "CN=lan.nt,CN=Deleted Objects,DC=vinacorp,DC=vn"
# Bước 2: Entra Connect sẽ tự restore cloud user sau delta sync
# Hoặc restore thủ công trên cloud nếu cần gấp
Restore-MgDirectoryDeletedItem -DirectoryObjectId "aaa-bbb-ccc"
User [email protected] restored successfully.
Microsoft Identity Manager (MIM) – Tổng quan
MIM (trước là FIM – Forefront Identity Manager) là giải pháp on-prem cho tình huống phức tạp hơn Entra Connect.
| Tính năng | Entra Connect | MIM 2016 |
|---|---|---|
| Sync AD → Entra ID | ✅ Native | Cần MIM PCNS + MA |
| Sync nhiều nguồn (LDAP, SQL, HR...) | ❌ | ✅ Management Agents |
| Self-service password (on-prem) | SSPR với writeback | MIM Portal built-in |
| PAM (Privileged Access Mgmt) | ❌ | ✅ Bastion forest + time-bound access |
| Certificate management | ❌ | ✅ MIM CM |
| Phù hợp | Hầu hết doanh nghiệp | Enterprise phức tạp, multi-source HR |
| Lifecycle | Active, roadmap cloud | Extended support đến 2029 |
Microsoft khuyến nghị dùng Entra ID Governance (Lifecycle Workflows) thay thế MIM cho các triển khai mới. MIM vẫn phù hợp nếu có on-prem HR system (SAP, Workday on-prem) cần sync.
Tổng kết Module 37
Kiến thức cốt lõi
- ✅ Synced user: sửa trên AD, không sửa trực tiếp Entra
- ✅ Soft match: UPN/ProxyAddresses khớp → auto link
- ✅ Hard match: gán ImmutableId = Base64(ObjectGUID)
- ✅ Group không sync = sai OU filter → move group sang OU trong scope
- ✅ Disable AD user → AccountEnabled false trên Entra sau sync
- ✅ Xóa AD user → soft-delete cloud (30 ngày)
Lab đã thực hành
- 🔬 Lab A: Audit synced users, xem và fix duplicate proxyAddresses
- 🔬 Lab B: Soft match qua UPN, Hard match thủ công bằng ImmutableId
- 🔬 Lab C: Disable/Delete/Restore user theo lifecycle đầy đủ