DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 2787210 - Last Review: July 9, 2014 - Revision: 18.0

On This Page

PROBLEM

When you try to remove a domain from Microsoft Office 365 by using Windows PowerShell, you get the following error message:
Remove-MsolDomain : Unable to remove this domain. Use Get-MsolUser -DomainName<domain name> to retrieve a list of objects that are blocking removal.
At line:1 char:18
+ Remove-MsolDomain <<<< -DomainName <DomainName>
+ CategoryInfo : OperationStopped: (:) [Remove-MsolDomain], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.DomainNotEmptyException,Microsoft.Online.Administration.Automation.RemoveDomain

CAUSE

This issue occurs if one or more of the following conditions are true:
  • User accounts or groups are associated with the domain.
  • The proxies that correspond to the domain for all mail-licensed users and for all mail-enabled groups aren't removed. Office 365 blocks the deletion of a domain until the proxies that correspond to the domain are removed.
  • Lync Online Session Initiation Protocol (SIP) addresses are used by the domain.

SOLUTION

Use the Office 365 admin center to remove the domain. The Domain Manager in Office 365 will help admins remove any dependencies that block domain removal without having to use Windows PowerShell. 

For more info about how to remove a domain in the Office 365 admin center, go to Remove a domain (http://office.microsoft.com/en-us/office365-suite-help/remove-a-domain-HA102818535.aspx) .

Troubleshoot domain removal by using Windows PowerShell

Note that the following steps require admins to use Windows PowerShell.

Step 1: Check whether user names contain the domain name

Note You can also create a user view and then set the domain to the domain that you're trying to remove. Use this view to note the user names, and then change the user names so that the domain in question isn't part of the user name.

To check whether user names contain the domain name, follow these steps:
  1. Connect to Microsoft Azure Active Directory by using the Azure Active Directory Module for Windows PowerShell. To do this, open the Azure Active Directory Modules for Windows PowerShell, type the following cmdlet, and then press Enter. 
    Connect-MsolService
    Enter your admin credentials when you're prompted for them.

    For more info about how to connect to Azure AD, go to Connect to Azure AD (http://aka.ms/aadposh#BKMK_connect) .
  2. Run the following cmdlet:
    Get-MsolUser -DomainName [Domain] | fl UserPrincipalName
    For example, run the following, where the contoso.com placeholder represents the domain in question:
    Get-MsolUser -DomainName contoso.com | fl UserPrincipalName
  3. Examine the results, and then change the user principal name (UPN) so that the domain isn't used. The UPN is the same as the user name and the user ID property. You can use the Office 365 portal or Windows PowerShell to change the UPN. The goal is to have no results returned.

Step 2: Check email addresses

Note This step applies only if you have a subscription that includes Exchange Online.

Note If you're running the Azure Active Directory Sync tool, you can update email addresses from the on-premises environment.

To check email addresses, follow these steps:
  1. Connect to Exchange Online by using remote PowerShell. For more information about how to do this, go to the following Microsoft website:
    Connect to Exchange Online Using Remote PowerShell (http://technet.microsoft.com/en-us/library/jj984289(v=exchg.150).aspx)
  2. Find all users and groups that use the domain that you're trying to remove. To do this, run the following cmdlet. (In this cmdlet, contoso.com represents the domain in question).
    get-recipient | where {$_.EmailAddresses -match "contoso.com"} | fl Name, RecipientType, EmailAddresses
  3. In the output, note the value of the EmailAddresses property and the RecipientType property. For example, the output may resemble the following
    Name : John Smith RecipientType : UserMailbox EmailAddresses : {SIP:john@contoso.com, SMTP:john@contoso.com, smtp:john@contoso.onmicrosoft.com}
  4. Do one of the following, as appropriate for your situation:
    • If RecipientType is set to UserMailbox, you can use the Set-Mailbox cmdlet together with the EmailAddresses parameter to change the smtp, SMTP, and SIP addresses. To learn more about this cmdlet, go to the following Microsoft website:
      Set-Mailbox (http://technet.microsoft.com/en-us/library/bb123981(v=exchg.150).aspx)
      Or, you can remove the user or license. However, we don't recommend doing this.

      Note If this is the last administrator user, create a new global administrator, sign in, and then remove the problem user.
    • If RecipientType is set to MailUniversalDistributionGroup or MailUniversalSecurityGroup, you can use the Set-DistributionGroup cmdlet together with the EmailAddresses parameter to change the smtp and SMTP addresses. To learn more about this cmdlet, go to the following Microsoft website:
      Set-Distribution Group (http://technet.microsoft.com/en-us/library/bb124955(v=exchg.150).aspx)
      Or, you can remove the group. However, we don't recommend doing this. If you can't remove the group, follow the steps in the following Microsoft Knowledge Base article:
      2731947  (http://support.microsoft.com/kb/2731947/ ) "You don't have sufficient permissions" error when you try to remove or make a change to a distribution group in Office 365"
    • If the RecipientType is set to DynamicDistributionGroup, you can use the Set-DynamicDistributionGroupcmdlet together with the EmailAddresses parameter to change the smtp and SMTP addresses. To learn more about this cmdlet, go to the following Microsoft website:
      Set-DynamicDistributionGroup (http://technet.microsoft.com/en-us/library/bb123796(v=exchg.150).aspx)
      Or, you can remove the group. However, we don't recommend doing this. If you can't remove the group, follow the steps in the following Microsoft Knowledge Base article:
      2731947  (http://support.microsoft.com/kb/2731947/ ) "You don't have sufficient permissions" error when you try to remove or make a change to a distribution group in Office 365"

MORE INFORMATION

For more information, see the following Microsoft Knowledge Base article:
2284755  (http://support.microsoft.com/kb/2284755/ ) You get an error message when you try to remove a domain from Office 365
Still need help? Go to the Office 365 Community (http://community.office365.com/) website.

Applies to
  • Microsoft Office 365
  • Office 365 User and Domain Management
Keywords: 
o365 o365e o365p o365a o365022013 o365m KB2787210
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support