We unsynced all the contacts from Active Directory on-premises. However, one contact is still available in Microsoft 365. When we want to remove it from the Microsoft 365 portal, it will not let us, and it fails with an error. In this article, you will learn how to force remove a contact in Microsoft 365 with PowerShell.
Let’s look at what happens when we want to delete the contact in the Microsoft 365 admin center and what error appears.
- Sign in to the Microsoft 365 admin center
- Expand Users > Contacts
- Select the contact from the list
- Delete the contact


- Click Delete


The delete contact failed error appears.
The operation on Identity failed because it’s out of the current user’s write scope. The action ‘Remove-MailContact’, can’t be performed on the object because the object is being synchronized from your on-premises organization. This action should be performed on the object in your on-premises organization.


So what if you don’t have an on-premises organization anymore, and the contact is a leftover? Let’s look at the next step to force the removal of the contact.
To force remove the contact in Microsoft 365 (Exchange Online) using PowerShell, follow these steps:
Step 1. Install Microsoft Graph PowerShell
Run Windows PowerShell as administrator and Install Microsoft Graph PowerShell.
Install both the Microsoft Graph PowerShell and the beta version. That’s because you need to use the beta cmdlet to remove the contact.
Install-Module Microsoft.Graph -Force
Install-Module Microsoft.Graph.Beta -AllowClobber -Force
Important: Always update to the latest Microsoft Graph PowerShell module version before you run a cmdlet or script to prevent errors and incorrect results.
Step 2. Connect to Microsoft Graph PowerShell
Connect to Microsoft Graph PowerShell.
Connect-MgGraph -Scopes OrgContact.Read.All, Directory.ReadWrite.All, Directory.Read.All
Enter your global administrator credentials and accept the Microsoft Graph permissions request.
Step 3. Get all contacts in Microsoft 365 with PowerShell
Run the Get-MgContact PowerShell cmdlet to get the contact. This will list all the contacts.
Get-MgContact -All | Sort-Object DisplayName
The output appears.
DisplayName Id Mail MailNickname
----------- -- ---- ------------
Contact1 f1e8a63b-6961-4548-b7ea-caca8c7e5d47 [email protected] contact1
Now that you have the contact ID, you can double-check and run the command below to retrieve the contact.
Get-MgContact -OrgContactId "f1e8a63b-6961-4548-b7ea-caca8c7e5d47"
Let’s go to the next step and remove the contact in Microsoft 365.
Step 4. Force remove contact in Microsoft 365 with PowerShell
Run the command below to remove the contact permanently from Microsoft 365.
Note: You must use the Remove-MgBetaContact cmdlet because this has not yet been ported to the stable release.
Remove-MgBetaContact -OrgContactId "f1e8a63b-6961-4548-b7ea-caca8c7e5d47"
Step 5. Verify your work
Check that the contact is removed.
Get-MgContact -OrgContactId "f1e8a63b-6961-4548-b7ea-caca8c7e5d47"
The contact is removed successfully and no longer appears in the Microsoft 365 admin center.


That’s it!
Read more: Hard delete mailbox without deleting user account in Microsoft 365 »
Conclusion
You learned how to force remove a contact in Microsoft 365 with PowerShell. The only method to force remove the contact is to use the Microsoft Graph PowerShell cmdlet. It’s not possible with the Exchange Online PowerShell cmdlets. Remember that you need to install the Microsoft Graph Beta module to be able to use the cmdlet and remove the contact.
Did you enjoy this article? You may also like Block sign-in from shared mailboxes. Don’t forget to follow us and share this article.