Posted on:
Categories: Office 365
Description:

Trying to remove one of the existing domains from your Office 365 tenancy? This should be pretty easy as long as the following criteria are met:

1. Domain is not used for UPN addresses

2. Domain is not used for SMTP addresses associated with your recipients or Lync online users

 

If you try to remove the domain prior to meeting conditions above (for instance by running Remove-MsolDomain –force) you will get the error saying

Unable to remove this domain. Use Get-MsolUser –DomainName <domain name>  to retrieve a list of objects that are

blocking removal.

 

Depending on how your O365 users were created (through Directory Synchronization or directly in O365) you will either need to update UPNs and remove those addresses from your on-premises Exchange recipients or Office 365 cloud accounts.

Once the UPNs are changed and domain is released from recipient addresses, you can confirm that domain is not in use by executing the following cmdlets below.

 

CONNECT TO O365 FROM POWERSHELL:

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Connect-MSOLService

 

 

CONFIRM THAT DOMAIN IS NOT IN USE:

To confirm that domain is not used for UPN addresses:

Get-msoluser –DomainName "domain.com"  (where "domain.com" is the domain you are planning to remove from O365)

 

To confirm that domain is not used for SMTP addresses:

Get-recipient –ResultSize unlimited | where {$_.EmailAddresses –match "domain.com" }

 

To confirm that domain is not used for E-mail addresses associated with MSOL  Groups:

Get-msolgroup –All |where {$_.ProxyAddresses –match "domain.com" }

 

Once all 3 PowerShell scripts come back clean you can remove the domain from O365 by running Remove-MSOLDomain –DomainName