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 admin@yourdomain.onmicrosoft.com to admin@yourdomain.com).

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: http://community.office365.com/en-us/f/148/p/4303/17035.aspx.

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 https://ps.outlook.com/powershell/ -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 admin@yourdomain.com and [Old Name] is admin@yourdomain.onmicrosoft.com

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

Regards

Matt

,

  • Hello! Someone in my Facebook group shared this site with us so
    I came to look it over. I’m definitely enjoying the information.
    I’m bookmarking and will be tweeting this to my followers!
    Exceptional blog and great design.

  • Thanks for the kind words. I’m glad that you’re finding it useful.

    It’d be great to hear from you about what things in particular you find useful, and what you’d like to see more of.

  • This site was… how do I say it? Relevant!! Finally I’ve
    found something which helped me. Thanks!

  • What’s up, I wish for to subscribe for this webpage to
    obtain most recent updates, thus where can i do it please help out.

  • Matt Harrop

    This is the way that I have amended your guide:

    1. > $LiveCred = Get-Credential

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

    3. > $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -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 -credential $livecred

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

  • Josh Gibbs

    What about using this process to change all the users UPN Names? what would we need to change in the Script?

  • Pingback: Office 365 & Migration & AD: Synchronized/Migrated user showing wrong UPN in Office 365 – Sabrina's Blog()

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 ×