The Set‑MsolUserPrincipalName cmdlet has been deprecated along with the entire MSOnline module. As of March 2025, these commands will stop working in favor of the Microsoft Graph PowerShell SDK.
This article explains how to rename a UserPrincipalName (UPN) using the Update‑MgUser cmdlet.
Why Rename the UserPrincipalName?
Renaming the UPN in Azure AD can be useful in various scenarios:
✅ Aligning Office 365 UPNs with on-premises Active Directory UPNs
✅ Fixing issues where the on-prem domain suffix isn’t verified in Microsoft 365
✅ Standardizing UPNs after a domain migration or company rebranding
Whatever your reason, here’s how to do it with the modern Graph PowerShell module.
Install and Connect to Microsoft Graph PowerShell
First, make sure you have the module installed:
Install-Module Microsoft.Graph Then connect to Microsoft Graph with the necessary permissions:
Connect-MgGraph -Scopes User.ReadWrite.All How to Rename a Single UserPrincipalName
You can identify the user either by their existing UPN or their ObjectId. To verify details:
PS C:\> Get-MgUser -UserId lene.hau@azure.skrubbeltrang.com | Select DisplayName, Id, UserPrincipalName DisplayName Id UserPrincipalName ----------- -- ----------------- Lene Hau 97d3bc7f-8ee6-4974-9115-c33087ad5600 Lene.hau@azure.skrubbeltrang.com
Rename using UserPrincipalName as identifier:
Update-MgUser -UserId lene.hau@azure.skrubbeltrang.com `
-UserPrincipalName lhau@azure.skrubbeltrang.com Rename using ObjectId as identifier:
Update-MgUser -UserId 97d3bc7f-8ee6-4974-9115-c33087ad5600 `
-UserPrincipalName lhau@azure.skrubbeltrang.com How to Bulk Rename UserPrincipalNames
If you need to update UPNs for many users—for example, changing a domain suffix from @oldcompany.onmicrosoft.com to @newcompany.com:
# Get users with old domain suffix
$Users = Get-MgUser -All | Where-Object {
$_.UserPrincipalName -like "*@oldcompany.onmicrosoft.com"
}
# Update UPN for each user
foreach ($User in $Users) {
$NewUPN = $User.UserPrincipalName.Replace(
"@oldcompany.onmicrosoft.com", "@newcompany.com"
)
Write-Host "Updating $($User.UserPrincipalName) to $NewUPN"
Update-MgUser -UserId $User.Id -UserPrincipalName $NewUPN
}
✅ Tip: Always verify the $Users list before running the update loop to avoid unintended changes.
The Bottom Line
Microsoft Graph PowerShell is powerful—but also complex, with long cmdlets, tricky permissions, and a steep learning curve. It’s a great tool for automation, but a terrible fit for first-line support.
This is where EasyEntra changes everything.
With its ADUC-style interface, even junior IT staff can handle tasks like renaming UPNs, syncing Azure AD Connect, and troubleshooting calendar permissions, without touching a single script.
No PowerShell. No escalations. No wasted time.
“One of the best products I’ve used.” – CIO, Mirick Law, United States
“We really love working with EasyEntra.” – Head of IT, IKN GmbH, Germany
“It feels almost like a revolution.” – IT Manager, Arjeplog Kommun, Sweden
👉 Try EasyEntra today—free for less than 25 licensed users.