How to use Set-MsolUserPrincipalName to rename Azure AD UserPrincipalName

The Set-MsolUserPrincipalName command will allow you to rename the UserPrincipalName of your Azure AD user account.

This can be useful in various scenarios.

One of the main reasons you’d want to use Set-MsolUserPrincipalName is to align your Office 365 UserPrincipalName with your on-premises UserPrincipalName.

There are many good reasons to keep your UserPrincipalName aligned in on-premises Active Directory and Azure AD. If, e.g., you use a domain suffix on-premises that hasn’t been verified in Office 365, you can get some “funny” results.

Whatever the reason, this is how to run it.

How to Rename the UserPrincipalName Attribute in Azure AD

You can use the ObjectId or the UserPrincipalName to identify the object you want to rename.

In any case, make 100% sure you’re addressing the correct object, e.g., by extracting the naming information:

PS C:\> Get-MsolUser -UserPrincipalName | fl *name*,ObjectId

DisplayName       : Lene Hau
FirstName         : Lene
LastName          : Hau
SignInName        :
UserPrincipalName :
ObjectId          : 2df91b7a-78a7-47cf-b58c-e294f302fd71

The following example shows how to execute the Set-MsolUserPrincipalName command using the UserPrincipalName as the identifier:

Set-MsolUserPrincipalName -UserPrincipalName -NewUserPrincipalName

This example shows how to execute the Set-MsolUserPrincipalName command using the ObjectId as identifier:

Set-MsolUserPrincipalName -ObjectId 2df91b7a-78a7-47cf-b58c-e294f302fd71 -NewUserPrincipalName

How to Bulk Rename Azure AD UserPrincipalName

What if you’re facing a general problem and need to rename the UserPrincipalName of many users?

The below example will identify all Azure AD users with a UserPrincipalName ending with “” and replace it with “”:

$Users = Get-MsolUser | ? {$_.UserPrincipalName -Like '*'}
ForEach ($User In $Users){
  Set-MsolUserPrincipalName -ObjectId $User.ObjectId -NewUserPrincipalName $User.UserPrincipalName.Replace("", "")

Please take a good look at the $Users variable before executing it, and use it at your own risk!

How to Consolidate Active Directory and Office 365 Management?

If you would like to have Office 365 settings available in the AD Users & Computers tool, have a look at Easy365Manager.

Easy365Manager is a snap-in to AD Users & Computers that extends user properties with two new tabs.

This enables you to manage Office 365 licenses and mailbox settings without using the plethora of web consoles normally needed.

You can even manage tasks like calendar delegation, which normally require PowerShell:

Speed up your user and mailbox administration and empower your first-line support with an intuitive graphical user interface that requires minimal training.

Download the free 30-day trial and have Easy365Manager up and running in just a few minutes.