How to update domain names via PowerShell or Graph API in bulk when we have to switchover from ABC.com to XYZ.com in M365 tenant?

Vinod Survase 4,776 Reputation points
2023-12-17T10:53:52.89+00:00

How to update domain names via PowerShell or Graph API in bulk when we have to switchover from ABC.com to XYZ.com in M365 tenant?

Also what are prerequisites and implications we should be aware of if we do this in bulk if there are any potential issues with any of the services in M365 like EXO, SPO, ODB and Teams and others?

For Example: I want to change users UPN from ******@abc.com to ******@xyz.com in bulk via PowerShell or Graph API.

Microsoft 365 and Office Install, redeem, activate For business Windows
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Akhilesh Vallamkonda 15,320 Reputation points Microsoft External Staff Moderator
    2023-12-18T09:37:33.5066667+00:00

    Hi @Vinod Survase

    Thank you for posting your query on Q&A.
    I understand that you are trying to update the Domain name via PowerShell or Graph API and Change the users UPN from ******@abc.com to ******@xyz.com in bulk operation.
    To update the domain names, you should have the Global Administrator role and verified ownership of domain.
    You can set or change the domain name from the Microsoft 365 admin center or you can use PowerShell to change the domain name with the below PowerShell cmdlet.
    Connect your PowerShell to AzureAD

    Verify the existing domains in your tenant using:

    Get-MsolDomain
    

    cmdlet gets a list of domains in Azure Active Directory.
    To Add a new domain, use

    New-MsolDomain
    

    this cmdlet adds a domain to Azure Active Directory. In your case you use following cmdlet New-

    MsolDomain -Name xyz.com -Authentication Managed
    

    you must verify the domain before it can be used.

    To update the user's principal name, or user ID, of all users in your Azure Active Directory tenant you can use.

    Get-MsolUser | ForEach-Object { Set-MsolUserPrincipalName -UserPrincipalName $_.UserPrincipalName -NewUserPrincipalName ($_.UserPrincipalName -replace "abc.com", "xyz.com") }
    

    After successfully completion of the above steps set the new domain as the default domain by using the

    Set-MsolDomain -Name xyz.com -IsDefault $true
    

    The other side changing the domain name and user principal name (UPN) of your users in Azure Active Directory may cause some issues with their access and experience of Microsoft 365 services. which as below

    Site user ID mismatch in SharePoint Online (SPO), OneDrive for Business (ODB), User information not updated in Team, User sign-in issues, OneDrive sync issues. Please ensure to test these changes in a controlled test environment before applying them in production.

    I hope this answer helps! If you have any further questions, please feel free to ask.

    Reference: https://learn.microsoft.com/en-us/microsoft-365/enterprise/add-a-domain-to-a-client-tenancy-with-windows-powershell-for-delegated-access-pe?view=o365-worldwide

    https://learn.microsoft.com/en-us/powershell/module/msonline/set-msoluserprincipalname?view=azureadps-1.0

    https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/howto-troubleshoot-upn-changes

    Thanks,

    Akhilesh.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.