Office365: Changing the main login name for (UPN) for a user via PowerShell

0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×

After a bit more working with PowerShell and Office365 (which is really powerful by the way), I decided that whilst I’d reset my primary email address for the one and only admin user in my domain (In this post), I still wanted to change my main login name (i.e. my UPN). By this I mean I wanted to change the suffix on my login (i.e. from to

As you cant change certain information on the account your logged in to, and as I only have one account, I decided to go down the powershell route again – and I have to say it was well worth it!

The use of powershell with Office365 is really impressive – and whilst I’m definitely new to powershell its stuff like this that really gets me interested. So, enough with the gushing and onto how its done:

Changing the UPN in Office365 remotely

The first steps are much the same as in the previous post, but importantly you must download and install the Office365 module for PowerShell. There’s some instructions here (dont worry about all the SSO stuff, you just need the module installed). Just one last note – I got most of this solution from the Office365 community at:

So fire up PowerShell and off we go:

1. > $LiveCred = Get-Credential

2. Now you need to enter your office365 credentials in the popup

3. > $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection

3. > Import-PSSession $Session (note that if this command fails, you may have to use “Set-ExecutionPolicy RemoteSigned” first, but please make sure you understand the implications of this first).

4. > Connect-MsolService

5. > Set-MsolUserPrincipalName -NewUserPrincipalName [New Name] -UserPrincipalName [Old Name]

Note: [New Name] is and [Old Name] is

And then you’re done (big thanks to Allan Xu MS Moderator!!). You can login using your proper domain name




The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×