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 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, instead of our nice 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 -NewUserPrincipalName 

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 "" | where islicensed -eq $true | %{Set-MsolUserPrincipalName -userprincipalname $_.userprincipalname -NewUserPrincipalName($_.userprincipalname.replace("",""))}

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.


Leave a Reply

Avatar placeholder

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.