Couldn’t Delete this user because the account is synchronized

Prajwal Desai
Posted by Prajwal Desai

While deleting an orphaned user from O365, I got the error Couldn’t delete this user because the account is synchronized with your on-premises servers. You can delete the user from your on-premises server.

As per Microsoft, this issue may occur if one of the following conditions are true :-

  • Case 1 – The on-premises AD DS is no longer available. Therefore, you can’t manage or delete the object from the on-premises environment.
  • Case 2 – You deleted an object from the on-premises AD DS. However, the object wasn’t deleted from your cloud service organization. This is unexpected behavior.

"<yoastmark

I wanted to remove objects that were created through directory synchronization from Azure Active Directory (Azure AD). But the fact is you can’t remove the orphaned user account by using the Microsoft cloud service portal in Office 365, Azure, or Microsoft Intune or by using Windows PowerShell.

Couldn’t Delete this user because the account is synchronized with your on-premises servers

To fix “Couldn’t delete this user because the account is synchronized with your on-premises servers” issue, perform the below steps.

Step 1 – Install the Azure Active Directory Module for Windows PowerShell

First of all to manage users and organization settings in Office 365 via PowerShell, you need to install the Azure Active Directory PowerShell Module. This can be installed using PowerShell.

Right-click Windows PowerShell and choose Run as administrator. Type the below command and press Enter.

Install-Module -Name MSOnline

Type Y to install and import the NuGet provider. Next, type Y again to trust the repository.

Install the Azure Active Directory Module for Windows PowerShell
Install the Azure Active Directory Module for Windows PowerShell

Step 2 – Connect to Azure AD

After you install the Azure AD module, you can now connect to Azure AD using the command.

Connect-MsolService

When you enter this command, you get a sign in box. Type your Office 365 admin credentials and connect to Azure Active Directory via PowerShell.

Connect to Azure AD
Connect to Azure AD

Step 3 – Disable Directory Synchronization

In this step using the below command, disable directory synchronization.

Set-MsolDirSyncEnabled –EnableDirSync $false

When you enter the above command, confirm the operation by typing Y.

Disable Directory Synchronization
Set-MsolDirSyncEnabled –EnableDirSync $false

Step 4 – Check Directory Synchronization Status

You can find the directory sync status using the below command.

(Get-MSOLCompanyInformation).DirectorySynchronizationEnabled

Continue to run this cmdlet periodically until it returns False, and then go to the next step.

Check Directory Synchronization Status
Check Directory Synchronization Status

Step 5 – Delete the orphaned object

After you perform Step 4, don’t expect that you can delete the orphaned user object quickly. That’s because it may take 72 hours for deactivation. In my lab it took around 2 minutes and I could delete the orphaned object.

Now try to delete user object by using Windows PowerShell or by using the cloud service portal and it should work. Congratulations we have successfully fixed “Couldn’t delete this user because the account is synchronized with your on-premises servers” issue.

Finally to re-enable directory synchronization, run the following cmdlet :-

Set-MsolDirSyncEnabled -EnableDirSync $true
Share This Article
Prajwal Desai
Posted by Prajwal Desai
Follow:
Prajwal Desai is a Microsoft MVP in Intune and SCCM. He writes articles on SCCM, Intune, Windows 365, Windows Server, Windows 11, WordPress and other topics, with the goal of providing people with useful information.
7 Comments