M365 Cross Tenant Migration | Part III
In the previous post we have created the MailUsers to migrate, but Migration Batches can only hold 100 users at the same time to set in sync.
When migrating more than 100 users it is hard to track who is already in a batch and who isn’t. Off course it is easy to use an Excel sheet to track which mailbox is in which migration batch. We used for the creation of the “to migrate mailusers”, CustomAttribute1 with the value: CROSSTENANT. I’m gonna use that value to filter the users who are created for migration.
Getting ALL users to Migrate
Connect to TARGET Tenant : GetToTheCloudTarget.onmicrosoft.com
#Exchange Online Management v3 Powershell module
Install-Module -Name ExchangeOnlineManagement -RequiredVersion 3.0.0 -Force
#Connect to Exchange Online from SOURCE tenant
Connect-ExchangeOnline
Getting all the users in a variable and getting all users that are al ready syncing or in a migration batch
$mailusers = Get-MailUser -ResultSize Unlimited | Where-Object {$_.CustomAttribute1 -eq "CROSSTENANT"}
$migrationUsers = Get-MigrationUser -ResultSize Unlimited
To determine which users are already in a migration batch
$notMigrated = @()
ForEach ($Mailuser in $Mailusers){
if ($migrationUsers.identity -contains $Mailuser.PrimarySMTPAddress){
$batch = $migrationUsers | where-Object {$_.Identity -eq $Mailuser.PrimarySMTPAddress}
Write-Host "$($Mailuser.DisplayName) is allready in batch $($Batch.BatchId)"
}
else {
$object = [PSCustomObject]@{
PrimarySMTPAddress = $Mailuser.PrimarySMTPAddress
}
Write-Host "$($Mailuser.DisplayName) is not yet in a batch"
$notmigrated += $object
}
}
$ToMigrate = "C:\Temp\NotMigrated.csv"
$List = New-Item $toMigrate
#add a header to the csv
Add-Content $toMigrate "EmailAddress"
#add the mail addresses to csv which can be imported
ForEach ($item in $NotMigrated){
Add-Content $ToMigrate "$($Item.PrimarySMTPAddress)"
}
After running this, you have a table with all the PrimarySMTPAddresses of the MailUsers, that where created for migration, and which are not yet added to a batch.