Bize Ulaşın / Contact Us

Bulk Change Office 365 accounts UPN / Sign-in Names

21 / 09 / 2017 by AD, Azure, Office365 Yorum yok / No Comments

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
Adds the domain we wish to use (Custom / EMail) to first part by + “

You can also write the same command in this way

Hope it helps.

Resources used :



PowerShell Tip for Strings

Leave a Reply

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

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.