Bulk Change Office 365 accounts UPN / Sign-in Names

If you synced your on-premises Active Directory (AD) without setting your users UPN attribute to use their email addresses or the custom domain you added to Azure AD, your users will have Office 365 usernames like [email protected]

Changing the logon domain from the on-prem AD user settings will not help for existing users, but it works for new users.

So if you in need of changing those users Sign-in / UPN names, you can do that very easily with PowerShell.

To do that we will need to get a list of users need a UPN change, so we need to filter the all users list.

We want to get list of users

  • with *@onmicrosoft*
  • without *#EXT#* (There are external partner accounts, also Status could be filtered for Guest type)
  • without “*shener*” {“Me :)”}
  • without “*admin*” (Or your Global Admins)
  • without “*-*” and “*_*” characters

in their UPNs (UserPrincipalName)

And we get all listed users’ .ObjectId value by $_.ObjectId and use that for -ObjectId paramater.

get-msoluser -UserPrincipalName [email protected] | Select ObjectId, UserPrincipalName

Then we set the new UPN (-NewUserPrincipalName) by manipulating the existing UPN

Splits the String by @ sign (Example : [email protected] becomes two element of an array [0] is osman.shener and [1] is mycompany.onmicrosoft.com)
Adds the domain we wish to use (Custom / EMail) to first part by + “@mycompany.com

You can also write the same command in this way

Hope it helps.

Resources used :

Get-MsolUser

Set-​Msol​User​Principal​Name

PowerShell Tip for Strings

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

*

Kontrol / Control * Time limit is exhausted. Please reload CAPTCHA.