M365 Cross Tenant Migration | Part I

Tenant Migration
Reading Time: 6 minutes

Since the 1st of November 2022 Microsoft has released Cross-Tenant User Data Migration. With that there was a release of cross-tenant mailbox migration and cross-tenant OneDrive migration to make is easier for customers to consolidate different tenants.

In this part I will explain what to setup for a mailbox migration. Microsoft writes:

Cross-tenant mailbox moves use an invitation and consent model to establish an Azure Active Directory application used for authentication between tenants. Using Azure Enterprise Application with Mailbox Migration permissions and a client secret, admins can now manage the authorization and scoping of Exchange Online mailbox migrations from one tenant to another. Additional components, such as an organizational relationship and a migration endpoint, are also required.

I will show how to setup that App registration and will provide the PowerShell commands to use. I Also wrote a PowerShell script to use which will set it up automatically.

Situation

Company Target has bought Company Source. They will work together in the next year but both work already in the Microsoft 365. Company Target is a big company with Exchange Online, Teams, SharePoint and OneDrive as default applications for the users to use. Company Source works with there e-mail in Exchange Online and need to have there e-mail in the tenant of Company Target.

Company Target: GetToTheCloudTarget.onmicrosoft.com with a domain name: user@target.com
Company Source: GetToTheCloudSource.onmicrosoft.com with a domain name: user@source.com

Index

Target Tenant App Registraton

At first you need to create an App registration with the correct permissions at the Company Target tenant. The target tenant is the destination where to you want to consolidate the users and there data. In our example case: GetToTheCloudTarget.onmicrosoft.com will be the destination of the data.

01-AppRegistration
Figure 1 App Registrations Target Tenant

In Azure Active Directory you can select 1. App Registrations and next to 2. New Registration

02-AppRegistration
Figure 2 App Registrations Target Tenant

1. Enter a name: Cross Tenant Migration and select
2. Accounts in any organisational directory (Any Azure AD Directory – MultiTenant).
3. WEB https://office.com
4. Register

03-AppRegistration
Figure 3 App Registration Target Tenant

Write down the client ID and the tenant ID

04-AppRegistration
Figure 4 App Registration Target Tenant
  1. Click API Permissions
  2. Remove User.Read permissions
  3. Click Add a Permission
05-AppRegistration
Figure 5 App Registration Target Tenant

Select the APIs my organization uses and search for Office 365. Select Office 365 Exchange Online API.

06-AppRegistration
Figure 6 App Registration Target Tenant

Select Application permissions

07-AppRegistration
Figure 7 App Registration Target Tenant

Search for Migration and select Mailbox.Migration

08-AppRegistration
Figure 8 App Registration Target Tenant

After adding the permissions you need to Grand admin consent for [ORGANIZATION NAME]

09-AppRegistration
Figure 9 App Registration Target Tenant

Add a Client Secret by clicking 1. Certificates & secrets and 2. New client secret. Enter a description and select the preferred Expiration time.

Figure 10 App Registration Target Tenant

After adding the client secret you will find it in the VALUE column. Copy/paste it because it cannot be revealed once left the page.

(Back to Top)

Adding application to SOURCE tenant

After creating an App registration in the target tenant, you will need to add this application to the Source tenant. This can be done formatting an url with the correct information and run this in a browser:

https://login.microsoftonline.com/GetToTheCloudSource.onmicrosoft.com/adminconsent?client_id= application_id_of_the_app_you_just_created]&redirect_uri=https://office.com

(Back to Top)

Target Tenant Exchange Online Powershell

For the actual migration between the tenant, you will need an Exchange Endpoint and an Organization Relationship. Like when there is a migration between Exchange On-premises and Exchange Online, the Hybrid Config Wizard will create this for you. Now you have to do it yourself using some PowerShell commands. Start an elevated PowerShell window

#Exchange Online Management v3 Powershell module
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 3.0.0 -Force

#Connect to Exchange Online
Connect-ExchangeOnline

Preparing the Target Tenant you will need to have an Exchange Endpoint to receive the incoming mailboxes.

# Enable customization if tenant is dehydrated
$dehydrated=Get-OrganizationConfig | select isdehydrated
if ($dehydrated.isdehydrated -eq $true) {Enable-OrganizationCustomization}
$AppId = "[guid copied from the migrations app]"
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $AppId, (ConvertTo-SecureString -String "[this is your secret password you saved in the previous steps]" -AsPlainText -Force)

For $AppID you use the CLIENTID from figure 3. The password is what you wrote down in Figure 10

New-MigrationEndpoint -RemoteServer outlook.office.com -RemoteTenant "GetToTheCloudSource.onmicrosoft.com" -Credentials $Credential -ExchangeRemoteMove:$true -Name "Receive from GetToTheCloudSource" -ApplicationId $AppId

Now we can create an Organization Relationship. This is the TenantID from the tenant where the mailboxes are hosted currently.

$sourceTenantId=[GUID FROM FIGURE 3 CALLED DIRECTORY (TENANT) ID]
$orgrels=Get-OrganizationRelationship
$existingOrgRel = $orgrels | ?{$_.DomainNames -like $sourceTenantId}
If ($null -ne $existingOrgRel)
{
    Set-OrganizationRelationship $existingOrgRel.Name -Enabled:$true -MailboxMoveEnabled:$true -MailboxMoveCapability Inbound
}
If ($null -eq $existingOrgRel)
{
    New-OrganizationRelationship "Relation with GetToTheCloudSource" -Enabled:$true -MailboxMoveEnabled:$true -MailboxMoveCapability Inbound -DomainNames $sourceTenantId
}

(Back to Top)

Source Tenant

To prepare the source tenant you need to rerun the AdminConsent url formatted with the correct information:

https://login.microsoftonline.com/GetToTheCloudSource.onmicrosoft.com/adminconsent?client_id= application_id_of_the_app_you_just_created]&redirect_uri=https://office.com

We need to create a security group in https://admin.exchange.microsoft.com and go to Groups

Figure 1 Source Tenant Security Group

This security group have as members the users that needed to be migrated. In the Organizational Relationship we have to define the security group that is holding these users. We select Mail-enabled security.

Figure 2 Source Tenant Security Group

Provide a name for the security group and a description

Figure 3 Source Tenant Security Group

Assign an Owner of the group

Figure 4 Source Tenant Security Group

Add the members that needs to be migrated to the new tenant

05-crosstenant-secgroup
Figure 5 Source Tenant Security Group

Provide a Group Email Address for the group and click Next. After the summary select Create Group.

(Back to Top)

Source Tenant Relationship

The source tenant needs to have a relationship with the Target Tenant. Before we already created a part of the relationship in PowerShell at the Target Tenant.

Start an elevated PowerShell prompt

$targetTenantId=[guid id from source tenant called tenantid]
$appId="[application id of the mailbox migration app you consented to]"
$scope="Users To Migrate"
$orgrels=Get-OrganizationRelationship
$existingOrgRel = $orgrels | ?{$_.DomainNames -like $targetTenantId}
If ($null -ne $existingOrgRel)
{
    Set-OrganizationRelationship $existingOrgRel.Name -Enabled:$true -MailboxMoveEnabled:$true -MailboxMoveCapability RemoteOutbound -OAuthApplicationId $appId -MailboxMovePublishedScopes $scope
}
If ($null -eq $existingOrgRel)
{
    New-OrganizationRelationship "Relationship with GetToTheCloudTarget" -Enabled:$true -MailboxMoveEnabled:$true -MailboxMoveCapability RemoteOutbound -DomainNames $targetTenantId -OAuthApplicationId $appId -MailboxMovePublishedScopes $scope
}

Final

Now we have created an Organizational Relationship between GetToTheCloudTarget and GetToTheCloudSource with an Exchange Endpoint to migrate users from Source to Target.

(Back to Top)

Share and Enjoy !

Shares
Designer (23)

Stay close to the action—follow GetToThe.Cloud across social!
Deep dives and hands‑on how‑tos on Azure Local, hybrid cloud, automation, PowerShell/Bicep, AVD + FSLogix, image pipelines, monitoring, networking, and resilient design when the internet/Azure is down.

🔗 Our channels
▶️ YouTube: https://www.youtube.com/channel/UCa33PgGdXt-Dr4w3Ub9hrdQ
💼 LinkedIn Group: https://www.linkedin.com/groups/9181126/
✖️ X (Twitter): https://x.com/Gettothecloud
🎵 TikTok: https://www.tiktok.com/@gettothecloud
🐙 GitHub: https://github.com/GetToThe-Cloud/Website
💬 Slack: DM us for an invite
📲 WhatsApp: DM for the community link

We use cookies to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners. View more
Cookies settings
Accept
Privacy & Cookie policy
Privacy & Cookies policy
Cookie name Active

Who we are

Our website address is: https://www.gettothe.cloud

Comments

When visitors leave comments on the site we collect the data shown in the comments form, and also the visitor’s IP address and browser user agent string to help spam detection. An anonymized string created from your email address (also called a hash) may be provided to the Gravatar service to see if you are using it. The Gravatar service privacy policy is available here: https://automattic.com/privacy/. After approval of your comment, your profile picture is visible to the public in the context of your comment.

Media

If you upload images to the website, you should avoid uploading images with embedded location data (EXIF GPS) included. Visitors to the website can download and extract any location data from images on the website.

Cookies

If you leave a comment on our site you may opt-in to saving your name, email address and website in cookies. These are for your convenience so that you do not have to fill in your details again when you leave another comment. These cookies will last for one year. If you visit our login page, we will set a temporary cookie to determine if your browser accepts cookies. This cookie contains no personal data and is discarded when you close your browser. When you log in, we will also set up several cookies to save your login information and your screen display choices. Login cookies last for two days, and screen options cookies last for a year. If you select "Remember Me", your login will persist for two weeks. If you log out of your account, the login cookies will be removed. If you edit or publish an article, an additional cookie will be saved in your browser. This cookie includes no personal data and simply indicates the post ID of the article you just edited. It expires after 1 day.

Embedded content from other websites

Articles on this site may include embedded content (e.g. videos, images, articles, etc.). Embedded content from other websites behaves in the exact same way as if the visitor has visited the other website. These websites may collect data about you, use cookies, embed additional third-party tracking, and monitor your interaction with that embedded content, including tracking your interaction with the embedded content if you have an account and are logged in to that website.

Who we share your data with

If you request a password reset, your IP address will be included in the reset email.

How long we retain your data

If you leave a comment, the comment and its metadata are retained indefinitely. This is so we can recognize and approve any follow-up comments automatically instead of holding them in a moderation queue. For users that register on our website (if any), we also store the personal information they provide in their user profile. All users can see, edit, or delete their personal information at any time (except they cannot change their username). Website administrators can also see and edit that information.

What rights you have over your data

If you have an account on this site, or have left comments, you can request to receive an exported file of the personal data we hold about you, including any data you have provided to us. You can also request that we erase any personal data we hold about you. This does not include any data we are obliged to keep for administrative, legal, or security purposes.

Where we send your data

Visitor comments may be checked through an automated spam detection service.
Save settings
Cookies settings