Change Non-user Object UPN to onmicrosoft.com Domain Using Microsoft Graph PowerShell

Target

Customers using HENNGE Access Control Directory Sync to synchronize users to Microsoft 365 are the target audience.
(Excludes cases where user synchronization is performed from Active Directory.)

Purpose

When synchronizing from HENNGE Access Control to Microsoft 365, this procedure excludes meeting rooms, equipment, and shared mailboxes that are not user objects from the synchronization.

Notes

1. The content of this article is based on the product information as of January 2024 and may be subject to change without notice thereafter.

2. It may take some time for this setting to be reflected in the Microsoft 365 admin center.

Detailed Steps and Explanation

Pre-Check

1. Prepare an environment where you can connect to Microsoft 365 from Microsoft Graph PowerShell.

Refer to the following article to ensure that you can connect to Microsoft 365 from Microsoft Graph PowerShell:

Connect to Microsoft 365 from Microsoft Graph PowerShell

1. Execute PowerShell Commands

1.1. Open [Start] on Windows, and open [Windows PowerShell] as an administrator.

※ Make sure that [Administrator] is displayed in the upper left corner of the opened PowerShell.

1.2. Execute the following command to connect to Microsoft Graph.

Connect-MgGraph -Scopes "Organization.Read.All","User.ReadWrite.All"

1.3. When prompted for Microsoft 365 credentials, sign in to Microsoft 365 with an account that has [Global Administrator] permissions and click [Consent].

1.4. Execute the following command:

Example:

Update-MgUser `
-UserID "XXX@example.com" `
-UserPrincipalName "XXX@YYY.onmicrosoft.com"

- Specify the current UserPrincipalName of your custom domain for -UserID.
- Specify the UserPrincipalName with the domain part changed to onmicrosoft.com for -UserPrincipalName.

1.5. Execute the following command:

Example:

Get-MgUser -UserID "XXX@YYY.onmicrosoft.com" ※ After the UPN change

- Confirm that the UPN has been changed to what you entered in step 1.4.
- Also, confirm that the email address has been changed to the same value.
- If there is no need to correct the email address, proceed to "1.8. Disconnect from Microsoft Graph."

1.6. If you need to change the email address, execute the following command:

Example:

Update-MgUser `
-UserID "XXX@YYY.onmicrosoft.com" `
-Mail "XXX@example.com"

- Specify the UserPrincipalName of the onmicrosoft.com domain that you changed in step 1.5 for -UserID.
- Specify the primary email address you want to change for -Mail.

1.7. Execute the following command again:

Example:

Get-MgUser -UserID "XXX@YYY.onmicrosoft.com"

- Confirm that the primary email address displayed in Mail has been changed to what you entered in step 1.6.

1.8. Disconnect from Microsoft Graph

Execute the following command to disconnect from Microsoft Graph:

Disconnect-MgGraph

※ The [Connect-MgGraph] command retains the previously authenticated credentials without requiring you to sign in the next time you start. Therefore, it is necessary to execute [Disconnect-MgGraph] to ensure that the sign-in is disconnected.

          
Was this article helpful?