Sync Azure cloud only account to an on-premise Active Directory
Context
Azure AD Connect acts as a gateway between the on-premises Active Directory and the Azure tenant.
If you haven’t created the account yet for person X in the cloud, setup will only take 5 minutes max (create the AD on-prem account and perform a delta sync).
However, a problem arises if you’ve already created cloud-only users in Azure and want to sync them with your on-prem AD.
Solution
The solution is first to delete duplicate users and keep the originals. In this case, the original user is "apes", so the other one must be removed.
Next, I run this PowerShell script to perform the sync.
Step-by-step Script Breakdown
Connect to Office 365 Admin
The script prompts for admin credentials and connects to the Microsoft Online (Office 365) service using the MsOnline
module. This enables access to cloud users for later modifications (~30 seconds).
Temporarily Disable Directory Sync
Directory synchronization between Azure AD and the local Active Directory is disabled to avoid conflicts during user linking. The script confirms the sync is effectively disabled before proceeding (~5 seconds).
User Selection and Linking
The script displays an interactive grid to select a local AD user, converts their ObjectGUID
to ImmutableID
, then allows you to select a cloud user to link. The ImmutableID
is then applied to the cloud user to establish the match. This process repeats as long as you wish to link more accounts (~60 seconds).
Check ImmutableIDs
Once the linking is complete, the script shows a grid listing all cloud users with their ImmutableID
for visual verification (~10 seconds).
Reactivate Sync
Directory synchronization is re-enabled and a delta sync is triggered to apply the changes in Azure AD. This ensures the links are correctly propagated (~15 seconds).
Cleanup and Close
The script closes all open PowerShell sessions to free up resources. (~3 seconds).
PowerShell Script
Script Execution
In the first window, select the local AD user "apes".
Then in the second window, choose the Azure AD user you wish to sync with.
After syncing, the script will ask if you want to continue linking other users.
If you type "N", a window will simply display users with their "ImmutableId".
As you can see in Azure AD, the user "apes" is now synced. Yes!