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.
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 examples
Stands for
demo1source.onmicrosoft.com
The old (source) tenant, where the mailboxes are today
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.
Phase 1 of 8 · Step 1
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.
What you should seeNo errors. The folder C:\mig exists.
Phase 2 of 8 · Steps 2 to 4
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.
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.
Phase 3 of 8 · Steps 5 to 7
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.
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.
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.
What you should seeAll 2 users listed in MigUsers. ToNewTenant shows RemoteOutbound, the app ID and {MigUsers}.
Phase 4 of 8 · Steps 8 to 10
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).
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.
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.
Phase 5 of 8 · Steps 11 to 13
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.
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%.
Phase 6 of 8 · Step 14
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].
Phase 7 of 8 · Steps 15 to 18
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.
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.
Domain
Type
Name
Value
demo1.example
MX
@
demo1-example.mail.protection.outlook.com (or the value shown), priority 0
CNAME
autodiscover
autodiscover.outlook.com
TXT
@
v=spf1 include:spf.protection.outlook.com -all
demo1mail.example
MX
@
demo1mail-example.mail.protection.outlook.com (or the value shown), priority 0
CNAME
autodiscover
autodiscover.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.
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.
Phase 8 of 8 · Steps 19 to 20
Users and cleanup
Prove mail flows both ways, get everyone signed in, then remove everything the migration created.
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.
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 see
Cause
Fix
AADSTS7000215 in the sign-in test
The 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 test
The 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 test
The secret was empty when pasted.
Paste with a right-click in the PowerShell window. Step 4
accessingTenant and resourceOwnerTenant should not be equal
You 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-OrganizationCustomization
Organization customization is still being applied.
An 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.