Felix Cloud/Insights

Cross-tenant mailbox migration in PowerShell: all 20 steps.

The exact commands we run to move Microsoft 365 mailboxes from one tenant to another, in order, with what you should see after each one and the errors that stop most first attempts.

Envelopes passing through a gate from one side to the other

Our tenant migration guide explains what a tenant-to-tenant mailbox move is and when to use Microsoft's native method. This post is the hands-on version: every command, in the order we run them, for the native cross-tenant mailbox migration in Exchange Online.

How to read the commands

The commands below use a made-up company so you can see where each name goes. Swap in your own, or let the tenant move runbook fill them in for you.

In the examplesStands for
demo1source.onmicrosoft.comThe old (source) tenant, where the mailboxes are today
demo1target.onmicrosoft.comThe new (target) tenant, where they are going
demo1.example, demo1mail.exampleThe custom email domains that move with them
[email protected], [email protected]The people who are moving
C:\migA working folder on your PC
<APP-ID-FROM-STEP-2>The Application (client) ID you get in step 2
Old tenantNew tenantAdmin portalYour PC
  • Two PowerShell windows. One stays signed in to the new tenant from step 4 onward, the other to the old tenant from step 7. Each step's label says which one to use.
  • A Global Admin in each tenant. The old tenant's admin approves the app; the new tenant's admin does most of the work.
  • Mail only. OneDrive files and Teams chats do not move with the mailbox. Check them before anything in the old tenant is removed.

Prepare

One module, one folder and two things that need lead time: the migration licences and a lower DNS time-to-live.

01Your PC · PowerShell

Prepare your PC

Install the Exchange Online PowerShell module and create the working folder. Run once, in a normal PowerShell window.

  • Buy one Cross-Tenant User Data Migration add-on per user (2 needed). Buying alone does nothing; you assign them in step 11.
  • A day before the cutover, lower the MX record TTL to 300 seconds for demo1.example, demo1mail.example.
PowerShell
Install-Module ExchangeOnlineManagement -Scope CurrentUser -Force
New-Item -ItemType Directory -Force "C:\mig" | Out-Null
What you should seeNo errors. The folder C:\mig exists.

Connect the tenants

A cross-tenant move is authorised by an app registration in the new tenant that the old tenant approves. Most failed migrations go wrong here, so step 4 tests the sign-in before Exchange gets involved and hides the real error.

02New tenant · portal

Create the migration app in the new tenant

Sign in to entra.microsoft.com as [email protected].

  1. Applications → App registrations → New registration. Name it TenantMoveApp.
  2. Supported account types: Multiple Entra ID tenants / Accounts in any organizational directory.
  3. Redirect URI: platform Web, value https://office.com. Register.
  4. API permissions → Add → APIs my organization uses → Office 365 Exchange Online → Application permissions → Mailbox.Migration. Then Grant admin consent.
  5. Certificates & secrets → New client secret. Copy the Value column (about 40 characters) into a password manager. Not the Secret ID.
  6. Copy the Application (client) ID from Overview. It replaces <APP-ID-FROM-STEP-2> in every later command.
What you should seeAPI permissions shows Mailbox.Migration (Application) with a green tick.
03Old tenant · portal

Approve the app in the old tenant

A Global Admin of the old tenant opens this link in a private browser window, signs in as [email protected] and clicks Accept.

Consent link
https://login.microsoftonline.com/demo1source.onmicrosoft.com/adminconsent?client_id=<APP-ID-FROM-STEP-2>&redirect_uri=https://office.com
What you should seeThe browser lands on office.com. In the old tenant's Entra → Enterprise applications, TenantMoveApp is listed.
04Your PC · PowerShell

Test the app sign-in

Catches a wrong secret or missing consent before Exchange hides the real error. Paste the secret Value when asked.

PowerShell
$appId  = "<APP-ID-FROM-STEP-2>"
$source = "demo1source.onmicrosoft.com"
$secretValue = Read-Host "Paste the secret VALUE"
"Secret length: $($secretValue.Length)  (expect about 40)"

$body = @{ client_id=$appId; client_secret=$secretValue; scope="https://outlook.office365.com/.default"; grant_type="client_credentials" }
try { Invoke-RestMethod -Method Post -Uri "https://login.microsoftonline.com/$source/oauth2/v2.0/token" -Body $body | Out-Null; "SUCCESS" }
catch { $_.ErrorDetails.Message }
Watch outKeep this window open: step 5 reuses $appId and $secretValue.
What you should seeSUCCESS. AADSTS7000215 = wrong secret (Secret ID used). AADSTS700016 = step 3 not done. AADSTS7000216 = the secret was empty; paste with right-click.

Exchange setup

Three objects make the route: a migration endpoint and an inbound relationship in the new tenant, and an outbound relationship in the old tenant, limited to a security group of the people who are moving.

05New tenant · PowerShell

New tenant: connect and create the migration endpoint

In the same window as step 4. If organization customization is not active yet, the second command enables it; that can take 15 minutes to a few hours.

New tenant window
Connect-ExchangeOnline -UserPrincipalName [email protected]
Get-OrganizationConfig | Select Name          # must show demo1target.onmicrosoft.com
Enable-OrganizationCustomization

$cred = New-Object System.Management.Automation.PSCredential($appId, (ConvertTo-SecureString $secretValue -AsPlainText -Force))
New-MigrationEndpoint -RemoteServer outlook.office.com -RemoteTenant "demo1source.onmicrosoft.com" `
  -Credentials $cred -ExchangeRemoteMove:$true -Name "SourceEP" -ApplicationId $appId
Watch outIf you see "accessingTenant and resourceOwnerTenant should not be equal", you are signed in to the old tenant. Disconnect-ExchangeOnline and sign in as [email protected].
What you should seeA line showing SourceEP ExchangeRemoteMove outlook.office.com. An error from Enable-OrganizationCustomization saying it is already enabled is fine.
06New tenant · PowerShell

New tenant: allow mailboxes in from the old tenant

Same window. Looks up the old tenant's ID and creates the Inbound relationship.

New tenant window
$sourceId = (Invoke-RestMethod "https://login.microsoftonline.com/demo1source.onmicrosoft.com/.well-known/openid-configuration").issuer.Split('/')[3]
$sourceId
New-OrganizationRelationship "FromOldTenant" -Enabled:$true -MailboxMoveEnabled:$true `
  -MailboxMoveCapability Inbound -DomainNames $sourceId
Get-OrganizationRelationship | Select Name, MailboxMoveEnabled, MailboxMoveCapability
What you should seeFromOldTenant True Inbound. If it asks for Enable-OrganizationCustomization, wait and retry.
07Old tenant · PowerShell

Old tenant: scope group and outbound relationship

Open a second PowerShell window for the old tenant and keep it open. The group limits which mailboxes the new tenant may pull; it is required even for one user.

Old tenant window
Connect-ExchangeOnline -UserPrincipalName [email protected]
Get-OrganizationConfig | Select Name          # must show demo1source.onmicrosoft.com
Enable-OrganizationCustomization

New-DistributionGroup -Name "MigUsers" -Type Security -PrimarySmtpAddress [email protected]
Start-Sleep 30
Add-DistributionGroupMember MigUsers -Member [email protected]
Add-DistributionGroupMember MigUsers -Member [email protected]

$targetId = (Invoke-RestMethod "https://login.microsoftonline.com/demo1target.onmicrosoft.com/.well-known/openid-configuration").issuer.Split('/')[3]
New-OrganizationRelationship "ToNewTenant" -Enabled:$true -MailboxMoveEnabled:$true `
  -MailboxMoveCapability RemoteOutbound -DomainNames $targetId `
  -OAuthApplicationId "<APP-ID-FROM-STEP-2>" -MailboxMovePublishedScopes "MigUsers"

Get-DistributionGroupMember MigUsers | Select DisplayName
Get-OrganizationRelationship | Select Name, MailboxMoveCapability, OAuthApplicationId, MailboxMovePublishedScopes
What you should seeAll 2 users listed in MigUsers. ToNewTenant shows RemoteOutbound, the app ID and {MigUsers}.

Prepare the users

Each mailbox needs a placeholder waiting in the new tenant: a mail user that carries the same ExchangeGuid. Export the IDs from the old tenant, check that nothing is in the way, then create the placeholders.

08Old tenant · PowerShell

Old tenant: export mailbox details

Old tenant window. Saves each mailbox's ID and legacy address, and makes sure every mailbox has an address in demo1source.onmicrosoft.com (the new tenant forwards to it until the cutover).

Old tenant window
Set-Mailbox [email protected] -EmailAddresses @{add="smtp:[email protected]"} -ErrorAction SilentlyContinue
Set-Mailbox [email protected] -EmailAddresses @{add="smtp:[email protected]"} -ErrorAction SilentlyContinue

$moving = @("[email protected]", "[email protected]")
Get-Mailbox -RecipientTypeDetails UserMailbox -ResultSize Unlimited | ? { $moving -contains $_.PrimarySmtpAddress } |
  Select DisplayName, Alias, PrimarySmtpAddress, ExchangeGuid, ArchiveGuid, LegacyExchangeDN,
    @{n='X500';e={($_.EmailAddresses | ? {$_ -like 'x500:*'}) -join ';'}},
    @{n='AllEmails';e={$_.EmailAddresses -join ';'}} |
  Export-Csv "C:\mig\source-mailboxes.csv" -NoTypeInformation
Import-Csv "C:\mig\source-mailboxes.csv" | Select DisplayName, PrimarySmtpAddress, ExchangeGuid, AllEmails | Format-List
What you should see2 rows. Each AllEmails includes smtp:<alias>@demo1source.onmicrosoft.com. If the alias in the export differs from the one you planned, use the exported alias in the later commands.
09New tenant · PowerShell

New tenant: check for existing accounts

New tenant window. The move cannot land on an account that already has a mailbox.

New tenant window
$upns = @("[email protected]", "[email protected]")
$upns | % { Get-User $_ -ErrorAction SilentlyContinue | Select DisplayName, UserPrincipalName, RecipientTypeDetails }
Get-Mailbox -RecipientTypeDetails UserMailbox | Get-MailboxStatistics | Select DisplayName, ItemCount, LastLogonTime
Watch outIf they exist and their mailboxes are empty: delete them in the admin center (Users → Active users → Delete user), then in Entra → Users → Deleted users → Delete permanently. Wait until the first command returns nothing. This erases those new-tenant mailboxes; skip it if they hold data and use a copy tool instead.
What you should seeNothing returned for these users: go to the next step. If any show UserMailbox or User, see the warning below.
10New tenant · PowerShell

New tenant: create the placeholder mail users

New tenant window. Creates one mail user per person, stamped with the old mailbox's ID. You type a temporary password for each; users change it at first sign-in.

New tenant window
$targetOnMs = "demo1target.onmicrosoft.com"
$sourceOnMs = "demo1source.onmicrosoft.com"
$src = Import-Csv "C:\mig\source-mailboxes.csv"
$aliasFor = @{ "[email protected]" = "user1"; "[email protected]" = "user2" }

foreach ($s in $src) {
  $alias = $aliasFor[$s.PrimarySmtpAddress.ToLower()]
  $upn = "$alias@$targetOnMs"
  $pw  = Read-Host "Temp password for $($s.DisplayName)" -AsSecureString
  New-MailUser -Name $s.DisplayName -DisplayName $s.DisplayName -Alias $alias `
    -MicrosoftOnlineServicesID $upn -Password $pw -ExternalEmailAddress "$alias@$sourceOnMs"
  $tries = 0
  do { Start-Sleep 10; $tries++ } until ((Get-MailUser $upn -ErrorAction SilentlyContinue) -or $tries -ge 30)
  if ($tries -ge 30) { Write-Warning "$upn did not appear after 5 minutes. Check the error above, then re-run for this user."; continue }

  $x500 = @("X500:$($s.LegacyExchangeDN)")
  if ($s.X500) { $x500 += $s.X500.Split(';') }
  Set-MailUser $upn -ExchangeGuid $s.ExchangeGuid -EmailAddresses (@("SMTP:$upn") + $x500)
  if ($s.ArchiveGuid -and $s.ArchiveGuid -ne '00000000-0000-0000-0000-000000000000') { Set-MailUser $upn -ArchiveGuid $s.ArchiveGuid }
}
Get-MailUser | Select DisplayName, ExchangeGuid, ExternalEmailAddress, @{n='Emails';e={$_.EmailAddresses -join ', '}} | Format-List
Watch outDo not give these accounts an Exchange license yet. Any @demo1source.onmicrosoft.com address in Emails makes the batch fail with "not an accepted domain".
What you should seeEach ExchangeGuid matches the export. ExternalEmailAddress ends in @demo1source.onmicrosoft.com. Emails holds only SMTP:…@demo1target.onmicrosoft.com and X500 entries.

Copy

Licences first, then the batch. The copy runs in the background while people keep working, and pauses at 95% until you say go.

11Either tenant · portal

Assign the migration licenses

In the admin center of the tenant where you bought the add-ons, open each user → Licenses and apps → tick Cross-Tenant User Data Migration → Save.

In the new tenant, if you also add a base plan now, expand Apps and untick Exchange Online.

What you should see2 of 2 add-ons show as assigned.
12New tenant · PowerShell

New tenant: start the migration batch

New tenant window. The batch copies in the background and stops at 95% (Synced) until you complete it. Users keep working in the old tenant.

New tenant window
"EmailAddress`[email protected]`[email protected]" | Set-Content "C:\mig\batch.csv"

New-MigrationBatch -Name "Demo1Batch1" -SourceEndpoint "SourceEP" `
  -CSVData ([IO.File]::ReadAllBytes("C:\mig\batch.csv")) `
  -TargetDeliveryDomain "demo1target.onmicrosoft.com" -AutoStart
What you should seeDemo1Batch1 Syncing ExchangeRemoteMove 2
13New tenant · PowerShell

Watch the copy until it reaches Synced

Run every 15–30 minutes. Validating and Provisioning come first, then Syncing. A 2 GB mailbox takes under an hour; 40 GB can take most of a day. You can close PowerShell in between.

New tenant window
Connect-ExchangeOnline -UserPrincipalName [email protected]   # only if the window was closed
Get-MigrationUser -BatchId Demo1Batch1 | Select Identity, Status, ErrorSummary | Format-List
(Import-Csv "C:\mig\source-mailboxes.csv").ExchangeGuid | % {
  Get-MoveRequestStatistics -Identity $_ | Select DisplayName, StatusDetail, PercentComplete, TotalMailboxSize, BytesTransferred }
Watch outFailed with "not an accepted domain": fix Emails as in step 10, then Remove-MigrationBatch Demo1Batch1 and run step 12 again. Stuck in Provisioning: check the licenses from step 11, then Stop-MigrationBatch / Start-MigrationBatch.
What you should seeEvery user Synced / AutoSuspended at 95%.

Complete

One command, at a quiet time. From here on, people work in the new tenant.

14New tenant · PowerShell

New tenant: complete the move

Pick a quiet time. After this, users work in the new tenant. Mail to the old addresses is forwarded, so nothing bounces.

New tenant window
Complete-MigrationBatch Demo1Batch1 -Confirm:$false

# re-run until every user shows Completed 100% (Synced 95% for a few minutes is normal)
(Import-Csv "C:\mig\source-mailboxes.csv").ExchangeGuid | % {
  Get-MoveRequestStatistics -Identity $_ | Select DisplayName, Status, PercentComplete }

(Import-Csv "C:\mig\source-mailboxes.csv").ExchangeGuid | % { Get-MailboxStatistics $_ | Select DisplayName, ItemCount, TotalItemSize }
What you should seeAll Completed, 100%. Item counts and sizes match the old mailboxes. Then assign each user their normal plan (for example Business Standard) with Exchange Online ticked, and test one sign-in at outlook.office.com as [email protected].

Domain cutover

The only part with a mail-flow window. Run steps 15 to 17 back to back, after hours.

15Old tenant · PowerShell

Old tenant: release the domains

Old tenant window, after hours. Moves the converted users onto demo1source.onmicrosoft.com and lists anything else still using the domains. Mail to the domains can bounce or queue until step 17 is done, so do steps 15–17 back to back.

Old tenant window
Set-MailUser [email protected] -MicrosoftOnlineServicesID [email protected]
Set-MailUser [email protected] -EmailAddresses "SMTP:[email protected]" -WindowsEmailAddress [email protected]

Set-MailUser [email protected] -MicrosoftOnlineServicesID [email protected]
Set-MailUser [email protected] -EmailAddresses "SMTP:[email protected]" -WindowsEmailAddress [email protected]

Get-Recipient -ResultSize Unlimited | ? { $_.EmailAddresses -match "demo1\.example|demo1mail\.example" } | Select DisplayName, RecipientTypeDetails, PrimarySmtpAddress
Watch outIf removal is blocked by an account with no mailbox (often an admin): Entra → Users → that account → Edit properties → Contact information. Change Email to its .onmicrosoft.com address and clear the domain from Other emails, wait 5 minutes, retry.
What you should seeThe last command returns nothing. Then in admin.microsoft.com (old tenant) → Settings → Domains, open each domain → Remove domain.
16New tenant · portal

Add the domains to the new tenant

admin.microsoft.com (new tenant) → Settings → Domains → Add domain, for each:

  • demo1.example
  • demo1mail.example

Add the TXT verification record at the DNS host and click Verify. If it says the domain is in use, wait 15–30 minutes for the old tenant to let go.

What you should seeBoth tenants agree: the old tenant no longer lists the domains, the new one shows them as Verified.
17DNS host · portal

Point DNS at the new tenant

Use the exact values the new tenant shows under Settings → Domains → [domain] → DNS records. Delete old MX records.

DomainTypeNameValue
demo1.exampleMX@demo1-example.mail.protection.outlook.com (or the value shown), priority 0
CNAMEautodiscoverautodiscover.outlook.com
TXT@v=spf1 include:spf.protection.outlook.com -all
demo1mail.exampleMX@demo1mail-example.mail.protection.outlook.com (or the value shown), priority 0
CNAMEautodiscoverautodiscover.outlook.com
TXT@v=spf1 include:spf.protection.outlook.com -all
What you should seeEach domain shows "No DNS issues" in the new tenant.
18New tenant · PowerShell

New tenant: give users their real addresses back

New tenant window. Adds every original address and makes the primary one the reply address.

New tenant window
Set-Mailbox [email protected] -EmailAddresses @{add="smtp:[email protected]"}
Set-Mailbox [email protected] -WindowsEmailAddress [email protected]

Set-Mailbox [email protected] -EmailAddresses @{add="smtp:[email protected]","smtp:[email protected]"}
Set-Mailbox [email protected] -WindowsEmailAddress [email protected]

Get-Mailbox -RecipientTypeDetails UserMailbox | Select DisplayName, PrimarySmtpAddress, @{n='Emails';e={$_.EmailAddresses -join ', '}} | Format-List
What you should seeEach user's PrimarySmtpAddress is their original address; X500 entries are still there. Then admin center → Users → each user → Manage username and email → set the username to the same address.

Users and cleanup

Prove mail flows both ways, get everyone signed in, then remove everything the migration created.

19Users · portal

Test mail and onboard users

  • From an outside account, send to every address: [email protected], [email protected], [email protected]. All must arrive in the new tenant.
  • Reply out from each mailbox and check it does not land in spam.
  • Users sign in at office.com with their usual address and the temporary password, change it and set up MFA.
  • Outlook desktop: new profile (Control Panel → Mail → Show Profiles → Add). Phones: remove and re-add the account.
  • Enable DKIM for each domain in the Defender portal → Email & collaboration → Policies → DKIM.
  • OneDrive and Teams data did not move. Check it before anything in the old tenant is removed.
What you should seeMail flows both ways for every address, and every user is signed in.
20New tenant · PowerShell

Clean up both tenants

Delete the app secret first: it can read mailboxes. Then remove the migration objects. Keep the old tenant's user accounts until OneDrive and Teams data is dealt with.

New tenant window
Remove-MigrationBatch Demo1Batch1 -Confirm:$false
Remove-MigrationEndpoint SourceEP -Confirm:$false
Remove-OrganizationRelationship FromOldTenant -Confirm:$false
Old tenant window
Remove-OrganizationRelationship ToNewTenant -Confirm:$false
Remove-DistributionGroup MigUsers -Confirm:$false
What you should seeThen delete TenantMoveApp in the new tenant's App registrations, remove it from the old tenant's Enterprise applications, and remove the migration add-ons from the users.

Errors and fixes

Every one of these came up in a real migration. The step link takes you to the command that fixes it.

What you seeCauseFix
AADSTS7000215 in the sign-in testThe Secret ID was used instead of the secret Value.Copy the Value column (about 40 characters). It is shown once; create a new secret if it is gone. Step 4
AADSTS700016 in the sign-in testThe old tenant has not approved the app.Open the consent link as a Global Admin of the old tenant. Step 3
AADSTS7000216 in the sign-in testThe secret was empty when pasted.Paste with a right-click in the PowerShell window. Step 4
accessingTenant and resourceOwnerTenant should not be equalYou are signed in to the old tenant while creating the endpoint.Disconnect-ExchangeOnline, then sign in as the new tenant's admin. Step 5
Asked to run Enable-OrganizationCustomizationOrganization customization is still being applied.Wait 15 minutes to a few hours and retry. Step 5
Batch fails with "not an accepted domain"A placeholder holds an address on the old tenant's domain.Fix the placeholder's addresses, remove the batch and start it again. Step 10
Batch stuck in ProvisioningThe migration licence is bought but not assigned.Assign it to each user, then Stop-MigrationBatch and Start-MigrationBatch. Step 11
"Domain is in use" when adding it to the new tenantThe old tenant has not let go yet.Wait 15 to 30 minutes and verify again. Step 16
Domain removal blocked in the old tenantAn account with no mailbox, often an admin, still holds an alias on the domain.Change its Email to the .onmicrosoft.com address and clear the domain from Other emails. Step 15

After the last step

Delete the app secret before anything else, because it can read mailboxes. Keep the old tenant's user accounts until OneDrive and Teams data has been dealt with, and remove the migration add-on licences once every mailbox shows Completed.

Skip the find and replace

The free runbook builds these same 20 steps with your tenants, domains and users filled in, and tracks your progress.

Talk to Felix

Want this run for you?

We run tenant-to-tenant migrations end to end, including the DNS cutover after hours. You get a plain-language plan and a quote, with no obligation.

  • +1 (866) FELIX-1TToll-free
  • +1 (647) 494-9872Toronto
  • [email protected]We reply within one business day
  • 1070 Sheppard Ave West, North York, ON M3J 0G8Felix IT Solutions Inc.