So you have a proof of concept Office 365 instance and you realize that you want to take things to Production, but you also realize that you want to keep your POC tenant up and oeprational. Caveat, you went through and applied your Domain Name to your tenant thorugh another registrar. How do you get your domain back?
Well, it’s not as difficult as you might think. Simply wander into the Office 365 Admin Portal over at https://portal.office.com/adminportal/
Under the “Setup” section of the Admin Center, you should see “Domains“. That will show you what domains you currently have associated with your Office 365 Tenant.
In my case I’ve got a custom domain, “potatoe.cloud” associated with my Office 365 tenant but still have my “onmicrosoft.com” domain as the default.
Step one to removing a domain is setting another domain as default. It’s pretty quick and easy, click on the other domain (in this case spsvabeach.onmicrosoft.com) and click “Set as Default.”
Next, within potatoe.cloud, I need to click on “Remove.” This should be simple enough.
Crikey! What’s this message at the bottom yammering about being enabled in the region? So essentially, I get to write a quick PowerShell script using some of the Azure AD components available over at the PowerShell Gallery – https://www.powershellgallery.com/packages/MSOnline/1.1.166.0
The gist of the script was running get-msoluser and feeding that to an array. From there looping through and modifying the UserPrincipalName’s domain name. Required a little more work than expected but in the end, worked quite nicely.
If you’ve only got a few users, probably easy enough to make this change through the Office 365 Admin UI. If you’ve got more than a few, PowerShell is your friend – working with arrays and foreach clauses to filter out the users you need to update to the “onmicrosoft.com” domain or another domain you’ve established and working.
After you get below a certain number of users (unknown what that is) with the non-offending domain remaining in the UPN, you can delete the domain from the tenant.
From there you can change your DNS settings back within your DNS registrar to continue making use of the domain or setting it up on your new Office 365 tenant that you’re actually switching over to use for production.
Nevertheless, be sure to try this all out in a test tenant and be mindful that if you’ve got a provider hosted app that’s looking for a specific domain name associated with a user and it’s changed, the user’s access may also have been changed with it. This is similar to if you have an on-premises application and you modify the user’s User Principal Name on-premises – applications that used to rely on that begin to break.
Bottom line – TEST! TEST! TEST!
After you’ve worked out the kinks, you should be good to go! Best of luck!