In short: I moved roughly 150,000 on-premises distribution groups and mail-enabled security groups to Exchange Online – about 80,000 simple ones and 70,000 nested ones – as a one-person team. The core trick is simple: build a prefixed copy in the cloud, retire the original through directory sync, then reveal the copy under the original name. Everything around it – discovery, data quality, dependencies and communication – is what made it work.
The starting point
The organisation ran hybrid Exchange, with every distribution group created and managed in on-premises Active Directory and synced to the cloud. The goal: groups mastered directly in Exchange Online, on-premises dependencies removed, and proper lifecycle management with owners and expiry dates. The project ran from autumn 2024 to spring 2026.
What made it hard was not the number of groups, but how they were used:
- Deep nesting in both directions – groups inside groups inside groups, and the same group sitting in several parents.
- Mixed types everywhere – distribution groups and mail-enabled security groups nested in each other, with members ranging from users and contacts to other groups and even computer accounts.
- Dependencies across the platform – the same groups granted access to SharePoint sites and Teams, Power BI workspaces, Azure resources, app registrations and Power Apps.
- Internal applications using distribution groups for authorisation – they shouldn’t, but many did.
- On-premises leftovers – groups containing on-premises mailboxes, room-booking policies and mailbox forwarding that pointed at groups.
Discovery first: a database, not a spreadsheet
Before migrating a single group, I spent a long time on inventory. With this many objects and relationships, spreadsheets stop working quickly, so I built a SQL Server database with dozens of tables and views, refreshed regularly by PowerShell import jobs.
The database held the full picture:
- Inventory – on-premises and cloud groups, members, owners, contacts, accepted domains, and the nesting structure, including which groups were leaves and who their parents were.
- Exclusions – empty groups, groups with members that weren’t synced to the cloud, application groups and explicit exclusions.
- Readiness views – “ready to migrate” lists for simple and complex groups, which the migration scripts read directly.
- Pre-migration checks – duplicate addresses and names, groups with several routing addresses, sender restrictions that pointed at other groups, groups sitting under non-mail parents.
- Impact queries – which groups granted access to SharePoint sites, Teams, Power BI workspaces, app registrations and Power Apps.
- Migration tables – schedule, status, a log of every step, and backups of the original objects.
On top of it, a Power BI report of around ten pages showed the status before and after, progress per wave, and the dependencies per service. It was the single place to answer “where are we?” – for me and for management.
Cleanup and communication
The cheapest group to migrate is the one you delete. Before the migration, group owners were asked to review their groups and remove what was no longer needed. About 8k groups were deleted before migration.
With tens of thousands of owners, the emails had to be automated too. I built Power Automate flows that read the list of affected groups, grouped them by owner, and sent each owner one email with a table of all their groups – in English and German, from a shared mailbox, with a short delay between messages to stay within sending limits. Different templates covered different situations: advance notices, post-migration notices, and special messages for owners of mail-enabled security groups whose groups were used in SharePoint.
Migration waves were grouped by domain and by owner, so each owner received one message per wave instead of one per group, and runs happened outside business hours.
The core idea: clone, retire, reveal
A group synced from on-premises can’t simply be converted into a cloud-managed group. So each group went through three phases: a new copy is built in Exchange Online next to the original, the original is retired through directory sync, and the copy then takes over the original’s name and addresses.
Phase 1 – Clone
- Create a new group in Exchange Online with a prefix (here
MIG_) on its name, alias, display name and every address, so it can exist next to the still-synced original without conflicts. It stays hidden from the address book. - Copy the settings: owners, moderation, sender restrictions, mail tips including translations, custom attributes and notes.
- Copy the original’s
legacyExchangeDNas an X500 address. This is the single most important routing detail: without it, replies to old messages and cached Outlook autocomplete entries bounce. - Add the tenant routing address (
alias@tenant.mail.onmicrosoft.com). Groups created in the cloud don’t get one automatically, but the on-premises contact from phase 2 needs it as its target. - Copy the members – see the 10,000-entry limit below.
- Fix the data along the way: groups whose owner was empty or pointed at an admin role group got a placeholder owner, and owners and allowed senders were resolved to real mailboxes, with anything else dropped and logged.
# Phase 1 – give every address a prefix, so the clone can coexist with the synced original
$prefix = "MIG_"
$smtp = $source.EmailAddresses | Where-Object { $_ -match '^smtp:' } |
ForEach-Object { $_ -replace ':', ":$prefix" }
# Keep the original legacyExchangeDN as an extra X500 address – this is what keeps
# replies to old messages and Outlook autocomplete working after the move
$x500 = @($source.EmailAddresses | Where-Object { $_ -match '^x500:' }) +
"x500:$($source.LegacyExchangeDN)"
$x500 = $x500 | ForEach-Object { $_ -replace 'Recipients/cn=', "Recipients/cn=$prefix" }
Set-DistributionGroup -Identity $clone.ExchangeObjectId -EmailAddresses ($smtp + $x500)
The members need two steps, because Update-DistributionGroupMember accepts at most 10,000 entries per call – the same limit I wrote about in the post on dynamic distribution groups:
$members = Get-DistributionGroupMember -Identity $source.ExchangeObjectId -ResultSize Unlimited |
Select-Object -ExpandProperty ExchangeObjectId
# Update-DistributionGroupMember accepts at most 10,000 entries per call
Update-DistributionGroupMember -Identity $clone.ExchangeObjectId -Members $members[0..9999] -Confirm:$false
# Anything above that goes one by one – one round trip per member, slow but reliable
if ($members.Count -gt 10000) {
foreach ($m in $members[10000..($members.Count - 1)]) {
Add-DistributionGroupMember -Identity $clone.ExchangeObjectId -Member $m
}
}
Phase 2 – Retire
- Back up the original first: attributes and the full member list, to a file and to the database. Not every on-premises member existed in the cloud, so this was the only complete record.
- For distribution groups: rename the original with a
decom_prefix on every unique attribute, hide it from the address book, and set the attribute the sync rules use to exclude it. The next sync cycle deletes its cloud copy. - For mail-enabled security groups: mail-disable the group on-premises, keep it as a plain security group with “(Security Group)” added to its name, and back up its mail attributes as JSON.
- Create an on-premises mail contact with the original addresses and X500, pointing at the routing address, hidden from the address book. An extension attribute holds a small JSON object that links the on-premises contact, the cloud group and the corporate directory entry. Each contact also gets an expiry date, randomised between 13 and 18 months, so renewals don’t all land in the same week.
- Nest the contact into every mail-enabled parent group on-premises, so those parents keep delivering to the migrated group. Object of type contact can only be member of a group by updating that group’s [Member] attribute.
...
$contactGadObj = get-adobject -filter "objectclass -eq 'contact' -and mail -eq '$($contactDefinition.origGroupMail)'" ...
$tempContactGadObj = get-adobject -filter "objectclass -eq 'contact' -and mail -eq 'temp_$($contactDefinition.origGroupMail)'" ...
...
Set-ADGroup -Identity $parentGrpObj `
-Server $parentBasicObj.canonicalname.substring(0,14) `
-Add @{member=$contactGadObj.ObjectGUID,$tempContactGadObj.ObjectGUID} `
-Credential $onPremCredential `
-Confirm:$confirm `
-WhatIf:$whatif `
-ErrorAction Stop
...
Phase 3 – Reveal
- Poll Exchange Online until the original group has disappeared – proof that the sync has run.
- Remove the prefixes from the new group, show it in the address book and mark it as cloud-managed, so the lifecycle automation adopts it.
- Remove helper contacts that were only needed during the transition.
Between the original disappearing and the prefixes being removed, mail to the group can bounce. Running the waves outside business hours kept that window harmless.
Nested groups: bottom-up, one layer at a time
About 70,000 groups contained other groups or were members of other groups. Migrating a parent before its children breaks membership, so the complex groups moved from the bottom up, with each layer completed before the next one started.
- When a leaf group migrates, its contact takes its place inside every on-premises parent.
- When the parent migrates later, its members include those contacts. The script reads the JSON link on each contact and adds the real cloud group as a member instead.
- Mail-disabled security groups had to be removed from their distribution-list parents, otherwise they blocked those parents from migrating.
- Readiness views in the database checked each layer before it ran: local mailboxes in the hierarchy, security groups inside it, and parents that weren’t mail-enabled.
Dependencies: what breaks when a group is recreated
A new group means a new object ID. Anything that granted access to the old group by ID loses that access: SharePoint and Teams permissions, Power BI workspace roles, Azure role assignments, app registrations and Power Apps sharing. Distribution groups should never be used for authorisation, but many were – especially the mail-enabled security groups.
- The impact queries listed, per group, which sites, workspaces, apps and roles depended on it, together with the owner and their division.
- Owners were told in advance, with the affected resources listed in their email.
- For mail-enabled security groups, we compared two methods and chose the one that keeps a single mail-enabled security group in the cloud, so it can be used for authorisation again.
- Because of the sheer complexity of how SharePoint permissions are applied (as roles, as permissions to content, links, etc.) I relied on the site collection admins to restore the permissions.
Built to be rerun
Running the same scripts tens of thousands of times means things will fail halfway through – throttling, replication delays, odd data. The scripts were built to be restarted at any point:
- Every phase reads its work list from the database and writes the group’s status after each step, so a run can stop and resume anywhere.
- Every step is logged to a database table and a transcript file.
- Calls to Exchange Online and Active Directory are retried with pauses, to ride out throttling and replication delays.
- “Already exists” and “address already in use” on a rerun are treated as success, which makes each phase idempotent.
- Unexpected errors pause the run instead of guessing. A person decides.
Lessons learned
- Discovery is the project. Most of the time went into understanding the data, not migrating it.
- Never trust attributes as they are. Owners, allowed senders and addresses all needed validating and resolving before they could be copied.
- Keep the legacyExchangeDN. Copying it as an X500 address is what makes a migrated group invisible to users.
- Find the groups used for authorisation early. They carry the real risk, not the mail flow.
- Be careful with automated deletes. A cleanup step meant for the old group once deleted a new one. It was removed from the process, not patched.
- Communicate per owner, not per group. One clear email per owner per wave, in their language.
- A one-person team needs automation everywhere. The database, the scripts, the emails and the report all fed each other.
Facing a similar migration?
I’m happy to talk through your environment and what would work for it. Get in touch.