When organizations manage their user identities through a synchronization process from On-Premise Active Directory to Azure AD, situations may arise where users are deleted on the On-Premise side but persist as orphaned entities in Azure AD. This can pose a challenge, especially when attempting to delete these users directly from the Azure AD interface, as the platform restricts such actions, stating, “You can only delete this user from your local Active Directory.”
Fortunately, PowerShell provides a solution for handling such users.
In order to achieve this, run Powershell as administrator and execute the following commands.
# Before starting ensure you have installed the MSOnline Module. If it’s not available on your computer, run the following command for installation.
Install-Module MSOnline
# Connect Azure AD with MsolService module
Connect-MsolService
# To remove the orphaned user, run the following command with the user’s UPN. In my test environment, the orphaned UPN is hector.bellerin@tayfntek.onmicrosoft.com
Remove-MsolUser -UserPrincipalName hector.bellerin@tayfntek.onmicrosoft.com
# Now you can check whether the orphaned user still exists.
Get-MsolUser -UserPrincipalName hector.bellerin@tayfntek.onmicrosoft.com