How to change username (UPN) in Microsoft365 using Powershell

Share This

If you’re reading this, you’re likely looking for a way to update the sign-in username (User Principal Name or UPN) in the Microsoft 365 Admin Center.

For cloud-only tenants, this process is quite straightforward. However, if you’re using Entra Connect Sync (formerly Azure AD Connect) to synchronize users from your on-premises Active Directory, it can become a bit more challenging.

There are various reasons why you might need to change a UPN—for example, a staff member who got married over the holidays or a student who legally changed their name via Deed Poll. Whatever the case may be, this tutorial will guide you through two simple methods to update UPNs using PowerShell.


Using Microsoft Graph (Newer)

1. Install Microsoft Graph

If you have never used Microsoft Graph, you’ll first need to install it using the CMDlet below

Install-Module -Name Microsoft.Graph

Once installed it will now need to be imported to the PowerShell session.

Import-Module Microsoft.Graph

Note: This could take a little longer than usual

2. Connect to Microsoft 365 Graph

Connect-MgGraph -Scopes "User.ReadWrite.All" -NoWelcome

You will be prompted to sign in. Login with your account and ensure the account has sufficient permissions. (Global Admin or User Admin)

3. Change the Username

To change a user’s User Principal Name (UPN) (their sign-in name and email):

# Define Variables
$OldUPN = "oldusername@yourdomain.com"
$NewUPN = "newusername@yourdomain.com"

# Update the UPN
Update-MgUser -UserId $OldUPN -UserPrincipalName $NewUPN

The UPN should now be updated.

4. Verify the UPN Change

Confirm the username (UPN) has updated by using the following CMDlet

Get-MgUser -UserId $NewUPN | Select-Object DisplayName, UserPrincipalName


Changing UPN Using Azure AD Module (Legacy)

Alternatively, for legacy purposes, you can use the Azure AD module:
1. Connect to Azure AD:

Connect-AzureAD

2. Update UPN:

Set-AzureADUser -ObjectId "oldusername@yourdomain.com" -UserPrincipalName "newusername@yourdomain.com"

3. Verify UPN Change:

Get-AzureADUser -ObjectId "newusername@yourdomain.com" | Select UserPrincipalName

Things to consider when changing Usernames (UPNs)

  • Propagation Time: Changes may take a few minutes to propagate across Microsoft 365 services.
  • Licenses and Services: Changing the username won’t affect licenses or other settings, but verify apps like Teams, SharePoint, and OneDrive still work.
  • Email Aliases: If users are heavily using their email, consider adding the old email address as an alias after updating the UPN.

Notes: If you receive Function capacity 4096 has been exceeded for this scope error while importing Microsoft Graph, try using PowerShell V7 (You can learn how to install Powershell v7 here.)

Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply

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