Employee offboarding sounds simple enough until you’re responsible for making sure every account, mailbox, license, session, and group membership has been handled correctly.
Now throw a hybrid Microsoft environment into the mix.
You’re working across Active Directory, Microsoft Entra ID, Exchange Online, and Microsoft 365. Each platform has its own administrative requirements, and completing an operation in one system doesn’t necessarily mean your work is finished in another.
After more than 20 years in IT, I’ve learned that some of the most frustrating infrastructure problems aren’t the complicated ones. They’re the repetitive ones that we’ve accepted as part of our everyday operations. Employee offboarding is a perfect example.
Disabling an Active Directory account isn’t enough
Disabling an Active Directory account is an important step, but a hybrid offboarding workflow needs to account for the broader Microsoft environment. Depending on the organization’s requirements, an employee offboarding checklist may include:
- Disabling the on-premises Active Directory account.
- Blocking Microsoft Entra ID sign-in.
- Revoking cloud sessions and refresh tokens.
- Preserving mailbox data when required.
- Configuring authorized email forwarding.
- Removing unnecessary Microsoft 365 licenses.
- Removing applicable cloud and on-premises group memberships.
- Documenting the results for verification and auditing.
Most experienced administrators already know how to perform these operations. Microsoft even publishes its own step-by-step guidance for removing a former employee.
The challenge is ensuring they’re performed consistently, in the appropriate order, and with enough visibility to confirm the intended results. That’s where automation becomes valuable.
Introducing OffboardPilot
OffboardPilot is an open-source PowerShell solution developed by Beyond Automation to coordinate employee offboarding across hybrid Microsoft environments. It’s published under the MIT License, and the full source is on GitHub.
The workflow is organized into six stages:
- Active Directory account disablement. The on-premises account is disabled using explicitly supplied admin credentials, so a least-privilege technician account can run the script.
- Microsoft Entra ID sign-in blocking. The cloud account is disabled through Microsoft Graph.
- Microsoft 365 session revocation. Active sessions and refresh tokens are revoked with Revoke-MgUserSignInSession.
- Mailbox and license management. The mailbox is converted to a shared mailbox, optional forwarding (and optional Full Access for the forwarding recipient) is applied, and assigned licenses are removed.
- Exchange Online group membership cleanup. Cloud-only distribution group memberships are removed.
- Active Directory group membership cleanup. On-premises group memberships are removed, including AD-synced distribution lists.
Before anything changes, the script runs pre-flight checks: it confirms the AD account, the Entra ID account, and whether an Exchange Online mailbox exists. Users with no mailbox are handled too. The Exchange steps are marked as skipped and the AD and identity steps continue normally.
At the end of execution, OffboardPilot generates a reconciliation report and a session transcript to help engineers review completed actions and identify anything requiring further attention. The goal is to make offboarding repeatable while maintaining appropriate operational control.
Watch the engineering demonstration
Our first Beyond Automation YouTube episode demonstrates OffboardPilot inside an operational hybrid infrastructure lab. You’ll see the initialization, authentication, configuration, execution, and reconciliation stages of the workflow.
This is actual lab execution, not simulated command output.
The player loads from YouTube in privacy-enhanced mode only after you press play. English captions are available from the CC button.
The Exchange Online problem that can be easy to miss
One of the more interesting challenges in developing offboarding automation involves how Exchange Online identifies recipients during mailbox and licensing changes.
When a workflow depends exclusively on a mutable email address or recipient property, changes made earlier in the process can affect later lookups. In OffboardPilot’s case, the concern is ordering: licenses are removed in step 4, and cloud group cleanup happens in step 5. After a license is removed, Exchange Online may revert the user’s primary SMTP address to the tenant’s onmicrosoft.com address. A group query that filters on the original email address can then come back empty.
An empty result isn’t an error. The script continues, reports that no memberships were found, and the user quietly remains a member of the distribution lists you meant to clean up.
OffboardPilot avoids that dependency. During pre-flight, before any mailbox or licensing change, it reads the mailbox with Get-Mailbox and stores the mailbox’s DistinguishedName. The distinguished name identifies the recipient object itself and doesn’t change when licensing is modified. Step 5 then uses that stored value to find group memberships:
# Pre-flight: capture a stable identifier before anything is changed
$EXOMailbox = Get-Mailbox -Identity $UserEmail -ErrorAction Stop
$EXOUserDN = $EXOMailbox.DistinguishedName
# ... Step 4 converts the mailbox and removes licenses ...
# Step 5: find cloud distribution group memberships by DN, not email address
$EXOGroups = Get-DistributionGroup -Filter "Members -eq '$EXOUserDN'"This is an excerpt from the released Invoke-UserOffboard.ps1, simplified for readability. If you want to see the effect in your own lab, the repository includes Get-EXOGroupMembership.ps1 so you can record a user’s cloud group memberships before and after a run.
Microsoft’s reference for filterable properties on the -Filter parameter and the Get-DistributionGroup documentation are worth reading if you’re building this kind of query yourself.
This is why understanding the relationships between systems matters more than simply combining PowerShell commands. The order of operations creates dependencies, and the automation has to account for them.
Automation should be verifiable
A script finishing successfully does not automatically mean every intended operation was successful. Infrastructure automation should provide enough information for engineers to understand what happened, what was skipped, and what requires additional attention.
That’s why reconciliation reporting is an important part of OffboardPilot. Every step reports one of three outcomes: completed, skipped (by design or by technician choice) or partially completed, and failed. The session transcript is written to disk so you have a record of exactly what ran.
Before deploying any offboarding automation in production, validate it against your organization’s retention requirements, licensing policies, administrative permissions, identity synchronization, and security procedures.
Shared mailbox conversion and license removal must account for mailbox size, archive functionality, retention, and other applicable licensing requirements. Microsoft documents the requirements for converting a user mailbox to a shared mailbox. OffboardPilot checks mailbox size before conversion. If the mailbox is 50 GB or larger, it stops and asks whether to convert anyway, apply forwarding only and keep the license, or skip the mailbox step for manual handling.
Why we’re embracing open source
Beyond Automation is moving toward a more collaborative approach to infrastructure engineering.
We want other engineers to inspect our work, understand the implementation, challenge our decisions, and adapt these solutions to their own environments. The best ideas don’t always come from the person who originally wrote the code.
That’s one of the reasons we’re making our engineering projects available through GitHub. The OffboardPilot README includes a lab guide that uses fictional users and a test domain, so you can contribute without touching production. If a test path behaves differently than documented, open an issue. The contribution guide explains how.
What are you still doing manually?
Employee offboarding is just one of many operational processes that can benefit from thoughtful automation. Look around your own infrastructure.
What are you repeatedly doing today that could become a better engineering solution tomorrow?
That’s the conversation Beyond Automation wants to encourage. Explore OffboardPilot, watch our demonstrations, contribute your ideas, and help us build better solutions for the engineering community.
Beyond Automation — Engineering Smarter IT Operations.