Skip to content

Instantly share code, notes, and snippets.

@RylandDeGregory
Created April 13, 2023 19:28
Show Gist options
  • Save RylandDeGregory/ca5a5a44ebea48a2d7c3d8daf10c293f to your computer and use it in GitHub Desktop.
Save RylandDeGregory/ca5a5a44ebea48a2d7c3d8daf10c293f to your computer and use it in GitHub Desktop.
Merge ADDS user with existing Azure AD user.
# Get the Immutable ID of the ADDS user
$Name = 'My Name'
$ADUser = Get-ADUser -Filter 'Name -like "*$Name*"'
$ImmutableId = [System.Convert]::ToBase64String($ADUser.ObjectGUID.tobytearray())
# Connect to Azure AD
Connect-AzureAD
# Remove the duplicated user from Azure AD that was created when the ADDS user was first synced
Remove-AzureADUser -ObjectId <duplicated AAD user ObjectId>
# Set Immutable ID of existing AAD user to the value obtained from the ADDS user
Set-AzureADUser -ObjectId <existing AAD user ObjectId> -ImmutableId $ImmutableId
# Start AAD Sync cycle
Start-ADSyncSyncCycle -PolicyType Delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment