Remove Domain from Office 365 Tenant using Powershell

If you ever tried the services of Office 365, it comes up with 30 days trial and starts de-provisioning the services after some time. You always have an option to pay as you go to Microsoft to continue that tenant. However, if you want to test or use it for one another month, you have to remove yourdomain.com from exiting expired Tenant, create a new O365 Tenant, and finally add yourdomain.com into it to continue using Office 365 services.

Let me walk you through the easy steps using Powershell to remove your domain from the expired tenant:

a) Open Powershell or ISE in Administrator Mode and connect to Msol Service:

$credential = Get-Credential  
Import-Module MsOnline
Connect-MsolService -Credential $credential

Note: Enter the Global Admin Credentials of Office 365 expired tenant in the popup.

b) If you have any data in any of your mailboxes, take the backup of the mailbox in .pst by first configuring it into Outlook. (in case there is no data, you can directly move to the next step).

c) Run the following commands in Powershell or ISE:

Get-Msoluser | Remove-MsolUser -force

Get-MsolUser -ReturnDeletedUsers | Remove-Msoluser -RemoveFromRecycleBin -force

Do check for any existing groups using yourdomainname.com and if any delete them using the below command.

Get-MsolGroup -all | Remove-MsolGroup -force

Note: Before removing your domain, make sure your domain name should not be used with any user’s email address, alias, groups, public folders, etc. Finally, go ahead and remove your domain:

Get-MsolUser -domainname YourDomainName.com | Remove-Msoluser -force

Note: It may take few minutes to remove the domain from the existing tenant.

d) Create a new Office 365 Tenant and add YourDomainName.com into it, re-publish its DNS records in the DNS Service Provider. Once verified, the status of yourdomain.com will become healthy.

e) Create Users with YourDomain.com and check the external mail-flow (Gmail to your new tenant).

Enjoy your new Office 365 Tenant with all services for another 30 days.

If you face any issue while adding yourdomain.com into new Office 365 Tenant using the GUI mode, you may also try the below PowerShell method:

Add Domain using Powershell to new Office 365 Tenant:

a) Connect to Office 365 Powershell with the new tenant’s [email protected] Global Admin (its the first Global Admin while creating a new tenant):

$credential = Get-Credential  
Import-Module MsOnline
Connect-MsolService -Credential $credential

b) Run the below Powershell Commands to add your domain to newly created Office 365 Tenant:

New-MsolDomain -Name YourDomainName.com

$txtrecord+=(Get-MsolDomainVerificationDNS -DomainName YourDomainName.com -mode dnstxtrecord)

$txtrecord | select-object Text,Label,TTL | Export-csv c:\TxtRecord.csv

Note: You will get a TxtRecord.csv file in your C:\ Drive. Copy the values from there and add it to your DNS Service Provider.

c) Come to Office 365 Admin Center (Left Pane) – Setup – Domains – Select Yourdomain.com – Check DNS – Microsoft will verify that you own yourdomain.com and will provide you 3 final records to start using Office 365 Services: Mx, Txt, Cname Records need to be added finally to your DNS Service provider.

d) Once all 3 records are published, click Verify and the Status of YourDomain.com will become healthy.

e) Create users with YourDomain.com email address and check Mail-Flow externally (from Gmail to YourDomain.com).

Thanks a ton for reading my above blog. If you have any comments, suggestions, or feedbacks please spare a second to post it.

Must check:

a) Create Skillshare Premium Account.

b) Create Lynda Premium Account.

c) Create LinkedIn Learning Premium Account for free.

d) Create Pluralsight Premium Account. 

Subscribe Us

Total Page Visits: 947 - Today Page Visits: 1

Add a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: