Force Remove Contact in Microsoft 365 with PowerShell

Listen to this Post

Featured Image
There may come a time when you’re unable to remove a contact in Microsoft 365 and receive an error stating that the contact is synced from your on-premises environment. However, you no longer have an on-premises environment, or you’re certain the contact is not being synced to the cloud.

The only solution is to forcefully remove the contact using PowerShell.

Learn more in the article below:

https://lnkd.in/ehqs_f-M

You Should Know:

Step-by-Step PowerShell Commands to Force Remove a Contact

1. Connect to Microsoft 365 PowerShell:

Connect-ExchangeOnline -UserPrincipalName [email protected]

2. Check Contact Sync Status:

Get-MailContact "[email protected]" | Select-Object Name, RecipientTypeDetails, IsDirSynced

3. Force Remove the Contact by Clearing ImmutableID:

Set-MailContact "[email protected]" -ImmutableId "$null"

4. Delete the Contact:

Remove-MailContact "[email protected]" -Confirm:$false

5. Verify Deletion:

Get-MailContact "[email protected]" 

(Should return an error if deleted successfully.)

Bulk Remove Contacts via CSV

If you have multiple contacts to remove, use a CSV file (contacts.csv) with a column EmailAddress:

$contacts = Import-Csv -Path "C:\path\to\contacts.csv"
foreach ($contact in $contacts) {
Set-MailContact $contact.EmailAddress -ImmutableId "$null"
Remove-MailContact $contact.EmailAddress -Confirm:$false
}

Additional Troubleshooting Commands

  • Check Sync Status for All Contacts:
    Get-MailContact | Where-Object {$_.IsDirSynced -eq $true} | Select-Object Name, PrimarySmtpAddress
    

  • Force Sync if Needed (Hybrid Environments):

    Start-ADSyncSyncCycle -PolicyType Delta
    

What Undercode Say:

Forcing the removal of a synced contact in Microsoft 365 requires overriding the directory sync lock. The key PowerShell commands involve clearing the `ImmutableId` attribute before deletion. This method is useful in hybrid environments where contacts get stuck due to sync errors.

For bulk operations, always verify the CSV import and test with a single contact first. Additionally, ensure proper admin permissions (Exchange Online Administrator role required).

For further automation, consider integrating with Azure AD PowerShell:

Connect-AzureAD 
Get-AzureADContact -SearchString "contactname" | Remove-AzureADContact 

Expected Output:

Contact removed successfully. 

For more details, refer to Microsoft’s official documentation on Exchange Online PowerShell.

Expected Output:

Name PrimarySmtpAddress IsDirSynced

<hr />

Test Contact [email protected] False 

(After removal, the contact should no longer appear in `Get-MailContact` results.)

References:

Reported By: Alitajran Microsoft365 – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

Join Our Cyber World:

💬 Whatsapp | 💬 Telegram