Changing users Domain in O365 tenancy

Cynthia Bachor
3 min readOct 11, 2021

Hello there O365 user, Welcome to a new week.

So last week, I had a client who wanted to change their email domains, and here is a solution that did work out well.

Case Scenario: Changing domain name of all users in O365 tenant from “OldCompanyDomain.com to NewCompanyDomain.com

Prerequisite: NewCompanyDomain.com must be verified in O365 https://docs.microsoft.com/en-us/microsoft-365/admin/setup/add-domain?view=o365-worldwide

Now here is what my environment looked like. I had some of my users with the default .onmicrosoft.com domain while some had my business domain name theyesshop.xyz

O365 Admin center (Active users)

To switch the domains of users from the old one to the new in this case from @theyesshop.onmicrosoft.com to @theyesshop.xyz, follow the steps below;

1. Launch Windows PowerShell

2. Connect to AzureAD by running the script

Connect-AzureAD

3. Sign into the global admin account

4. Run the script below

$domain = “NewCompanyDomain.com

Get-AzureADUser -All $True | Where { $_.UserPrincipalName.ToLower().EndsWith(“OldCompanyDomain.com”) } |

ForEach {

$newupn = $_.UserPrincipalName.Split(“@”)[0] + “@” + $domain

Write-Host “Changing UPN value from: “$_.UserPrincipalName” to: “ $newupn -ForegroundColor Yellow

Set-AzureADUser -ObjectId $_.UserPrincipalName -UserPrincipalName $newupn

}

Running the script and results

From the results, the users with the old domain name now have the new domain name

Users with new domain name

Some FAQs around this

1. Will Outlook reconfigure itself automatically for the new email domain?

Yes it will. If it doesn't, sign out and sign in with the new credentials.

2. Do users’ local OneDrive folder get renamed to “OneDrive — New Company Name”? If not, what would need to be done for OneDrive to reflect the new company name?

OneDrive desktop app will “heal” itself after a logout/reboot and does not require the user to do anything.

3. Do OneNote Notebooks get renamed to the new domain name, and will the local clients reflect this?

Because the links will continue to point to the old address, links to recently used documents stored in OneDrive will break, and shows a 404 error. my testing shows that this isn’t always the case, but it is most of the time. A work around is to change the domain name of the old one to the new and refresh. After that it syncs and you can access your notes again

So, for those who have an O365 subscription, have all of their emails with the default domain, and want to switch to their verified domains, as well as those who are rebranding and changing company names, I hope this is helpful.

--

--

Cynthia Bachor

Product manager with a background in AI and 4+ years of combined expertise in Product/Operations Management, Pre-sales activities and Technical Support