Probably like many people, I started testing out Office 365 in phases. One change that we had to make was to add a UPN alias for @domain.org to replace our @domain.local. I was a little leery of this, so I tested out some Office 365 features before adding the domain alias, including adding licenses to about 20 of our accounts.

The problem: those accounts that I just synced up were stuck with the ugly @domain.onmicrosoft.com domain, instead of our nice @domain.org alias. Forcing a resync did not resolve it.

This Technet article explains very clearly how to fix the problem:

Open Windows Azure Active Directory Module for Powershell, and then type in:

 
Set-MsolUserPrincipalName -UserPrincipalName user1@domain.onmicrosoft.com -NewUserPrincipalName user1@domain.org 

Simple, but I didn’t want to run this dumb command one at a time for each account. Simple enough in powershell, but I ran into a few gotchas so here is the successful command line I ran:

Get-MsolUser -domainname "domain.onmicrosoft.com" | where islicensed -eq $true | %{Set-MsolUserPrincipalName -userprincipalname $_.userprincipalname -NewUserPrincipalName($_.userprincipalname.replace("@DOMAIN.onmicrosoft.com","@domain.org"))}




One thing that took me a minute to remember after several runs with nothing happening is that string.replace() method is case sensitive, so make sure that you properly capitalize the UPN that you want to replace.

Follow me on social media:

Leave a comment

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