Automation · build story · updated November 2026

From my script to the team's runbook: automating onboarding and offboarding

It started as a spreadsheet-to-accounts script for one client. Now other techs use it too, with a template per client and short-lived tokens from my portal.

One of the clients I look after at work hires a lot. Around 30 new people a month, and some of them are only there for a few weeks, so really it's more like 60 onboardings and offboardings a month.

For a long time I did every one of them by hand. Then I got tired of it.

This story has two parts. The first is the script I built for that one client. The second is what happened when other techs wanted it for their clients too: it became AdminRunbook.

The AD Onboarding window: a drop zone for the onboarding spreadsheet at the top, Active Directory, Microsoft 365 and Offboarding sections with their buttons, and result cards underneath, one red conflict card and one green card
The first version, mid-batch. Everything here is from my lab: fake people, test domain.

How the requests show up

Two managers on the client's side fill in a spreadsheet, one row per person: display name, first name, last name, Windows username, temporary password and email. They email it to our support address as an attachment, and that opens a ticket.

The accounts live in on-prem Active Directory and sync up to Microsoft 365 with Entra Connect. So every new hire is really two jobs, one on each side.

The old way

One person took me about 15 minutes:

  • About 3 minutes to make the account in AD.
  • Run a sync and wait for them to show up in Microsoft 365.
  • Assign licenses and groups, then go back and check it all stuck.

Each extra person was a bit faster since I was already signed in to everything, but five of them still came to about 55 minutes. At this client's volume, that's a lot of afternoons.

The new way

Now I drop the spreadsheet on the tool. It reads the .xlsx itself (no Excel needed) and makes every account in one go. People with the same job title get pretty much the same access, so it sets their groups and licenses from the title too. My job is mostly reading the results.

Five people now take about 15 minutes. That's what one person used to take.

By handWith the tool
A batch of fiveabout 55 minabout 15 min
Per person, in a batchabout 11 minabout 3 min
A month at this clientroughly 8 minutes saved per hire, about 4 hours a month

What it actually does

It's one PowerShell script with a Windows Forms window on top. If there's no desktop (like when I run it from the RMM), it falls back to a text menu.

  • Review: checks every account against the spreadsheet. Names, email, title, company, which OU it's in, and its groups compared to a coworker's. Red means wrong, yellow means different but probably fine.
  • Onboard: shows me what each account is about to get and asks first. New accounts copy their OU and groups from a coworker or the job title's template. If the username or email already exists, that person gets a conflict card and nothing gets made.
  • Microsoft 365 check and fix: an Excel sheet lists what each job title gets: license, groups, distribution lists, shared mailboxes. The check marks each one OK, MISSING or CHECK MANUALLY. The fix is a list of checkboxes per person, and picking a template ticks everything for that title in one click.
  • Sync on demand: it kicks off an Entra Connect sync and waits for it. It only touches Microsoft 365 for people who've already synced, because making the cloud account first is how you end up with duplicates.
  • Offboarding: started as a check, then grew a fix button. It disables the account, moves it to the disabled users OU, hides it from the address list, pulls the groups, converts the mailbox to shared and removes the licenses. It can also pull someone back out of Microsoft 365's deleted users if they slipped through.

Nothing changes without a confirmation that lists the changes, the checks never change anything, and the console versions all take -WhatIf.

The create accounts dialog: job title Sales Associate, groups copied from a coworker, the standard users location, the sync group ticked, a summary of what every account gets, and four accounts listed with a Create 4 accounts button
It guesses the job title from the file name and copies groups from a coworker, then shows you everything before it makes anything.
A red conflict card: username already exists, not created, with the form's values side by side with the existing account's
This person already had an account, so no duplicate. Just a red card telling me why.
A review card: the display name doesn't match the form, and the groups line is flagged as not synced because the user isn't in the sync group
A typo in the display name, and someone who never got added to the sync group.
A Fix confirmation for one user listing the display name change and the two groups to add, with Yes, No and Cancel buttons
Fix asks one person at a time and spells out what it's going to change.

The mistakes I was trying to stop

Mailboxes vanishing the day after an offboarding. Not everyone knew that pulling someone out of the AD sync group deletes their Microsoft 365 account at the next sync. The offboarding would look done, then the sync would run later and quietly take the account with it, including mailboxes we meant to keep as shared mailboxes. So now the tool leaves the sync group alone unless you tick it on purpose, and the confirmation yells at you in capitals.

That's also why it always converts the mailbox to shared before removing any license. Take the license off a regular mailbox and it's gone 30 days later. If the convert fails, the licenses stay put. It also warns you if the mailbox is over 50 GB or on litigation hold, since those still need a license even as shared mailboxes.

The wrong license. About 90% of hires get one license and 10% get another, because some job titles need the desktop Office apps instead of the web versions. Muscle memory kept picking the common one. Now the license comes from the job title's template, and the check flags anything that doesn't match.

An offboarding check card with four problems: the account is still enabled, it's in the standard users location instead of disabled users, it isn't hidden from the address list, and five groups are still assigned
A placement that's ended but hasn't been offboarded yet. Still enabled, wrong OU, groups still hanging on.

Stuff that broke

My favorite one: shared mailboxes need the Exchange Online module, and licenses and groups need Microsoft Graph. Each module brings its own copy of Microsoft's sign-in library, and Windows PowerShell 5.1 can only load one per process. So whichever one signed in second just died with "Method not found".

I ended up running Exchange in its own little PowerShell process and having the main window send it commands. Which caused two new problems:

  1. I hid that helper window so it'd feel seamless, and got stuck in a sign-in loop. Now it shows up while you sign in, then hides.
  2. If the Exchange sign-in failed, it tried again for every single user. Now it fails once and the AD part carries on.

And a few smaller ones:

  • The license list was grayed out for one user, but worked for two. PowerShell 5.1 has a habit of not counting a single result properly, so one user counted as zero.
  • A screen label ended up in AD. A "(typed in)" tag that was only meant for the list on screen made it into someone's display name. Now names and email only ever get corrected from a form.
  • Enter applied changes. Hitting Enter in a search box clicked Apply. Now Enter doesn't apply anything, and every change goes through a confirmation.
  • "Not found" for someone who definitely exists. I only found this one rebuilding it in my lab for these screenshots. The offboarding check asks AD for two Exchange attributes, and in a domain that's never had Exchange, those don't exist, so AD threw out the whole lookup. Now it tries again without them.

How it got here

Version 1 was a short script I'd paste into PowerShell. Give it some usernames and it'd show title, company, email, location, description and whether the password had to change at next logon. That was it.

Everything after that came from a real ticket. Checking against the form, one window instead of five commands, conflict cards, job title templates, sync on demand, offboarding, protecting the sync group, typing usernames for one-off requests. It got to around 5,400 lines, and I still called it "the review script".

Then the other techs on my team started asking for it.

Part two: AdminRunbook

The problem with the review script was that everything in it was about one client: their OUs, their sync group, their job titles, their license mix. Handing it to someone else meant handing them a script full of another client's details and hoping they edited the right lines.

So I rebuilt it as AdminRunbook. It's still one PowerShell file, now with a proper WPF window, and it doesn't know anything about any client until you pick one.

AdminRunbook's User details page for a new hire at Harbour Dental Group, in dark mode: an onboarding checklist at 8 of 10 done, with the e-mail format and display name format marked wrong and everything else ticked, including the job title rule and its manual step
AdminRunbook in my lab, with a made-up client, Harbour Dental Group. Owen got set up with the wrong name and e-mail format, and the client's template caught both.

A template per client

Everything that used to be hard-coded now lives in a small template per client. The app picks the right one by itself when it sees that client's domain, and you can edit templates right in the app. Each template says:

  • What a good account looks like: the UPN suffix, which OUs new users belong in, the display name format ({first} {last} or {last}, {first}) and the e-mail format ({fi}{last} for jsmith, say).
  • What each job title gets: licenses, groups, distribution lists, shared mailboxes, plus the manual steps the app can't do, shown as notes so nobody forgets them.
  • What "offboarded" means for that client: disabled, hidden from the address list, in the disabled users OU, out of every group except the ones it should keep, sign-in blocked, licenses gone, mailbox converted to shared. A user only shows Done when all of that client's checks pass.
  • Whether there's an AD at all. Some clients are cloud only, so the app reads Microsoft 365 instead and skips anything that needs a domain controller.
The client template picker: three on-prem AD clients, one with a green dot because it matches the connected domain, and one cloud-only client
Pick a client, or let the app pick one. The green dot is the client whose domain it's connected to. (All four clients are made up.)
A client template's job title rules: hygienists and assistants get one license and the clinical groups, receptionists another license plus the front desk groups and printer, the practice manager a third license and the finance share, with manual steps in a notes column
Job title rules. This is where the "90% get one license, 10% get another" problem from part one went to die.
A client template's offboarding requirements: account disabled, in the disabled users OU and no groups left, then Microsoft 365 checks for sign-in blocked, licenses removed and mailbox converted to shared, with forwarding, MFA and devices as options
What "offboarded" means for this client. Each client gets its own boxes ticked.

Before a template is saved, the app shows exactly what's changing. That matters, because a template change affects every tech who works on that client.

The Update the HDG template dialog listing the one change, a note added to the Practice Manager rule, and asking for a write token that is used once and then revoked
Saving a template: here's what changes, and a write token that's only good for this one save.

Other techs, their own access

AdminRunbook runs locally, on the client's domain controller, with whatever rights the tech already has there. Getting it there wasn't the hard part. Knowing who did was. A copy on a file share, one shared password, or a token passed round in chat would all work, and none of them would tell me who pulled the app, when, or whether they were meant to.

So I wanted accountability: every copy tied to a real, verified person. The app lives in a private GitHub repository, and the only way to get it is through the client portal I'd already built. The portal already checks who everyone is (they sign in with Microsoft), already has admins to decide who's allowed, and already keeps an audit log. It just needed one more page.

What it looks like for a tech

  1. On the client's server, type one line: irm https://<portal>/run | iex. That launcher is public on purpose. It's a few lines of PowerShell with no secret in it, so there's nothing to steal.
  2. It opens the portal's AdminRunbook page in the browser. The tech signs in with their own Microsoft work account and clicks Get read token.
  3. The portal shows the token once. Copy it now, because it's never shown again and the portal doesn't keep it. It says exactly when it expires.
  4. Paste it back into PowerShell. The launcher downloads the app with it and hands the token straight to the app, so it unlocks without a second paste. The token only ever lives in memory.
  5. Close the app and it's gone. The downloaded copy gets deleted, and the token dies within the hour either way.

Who gets what

Nobody gets access by default. Someone has to be put there by an admin, and the portal checks against the database at the moment the token is issued, not just when you signed in.

WhoRead token (run the app)Write token (save templates)Change who's on the list
Admin who can manage admins✓✓✓
Any other portal admin✓✗✗
Tech an admin added to the list✓✗✗
Tech on the list marked "Can save templates"✓✓✗
Anyone else from our own tenant✗✗✗
Anyone from a client's tenant✗✗✗
  • Techs on the list aren't admins. They sign in to the same portal, but the only page they can see is the AdminRunbook one. No client list, no requests, no settings.
  • Write is rare on purpose. Running the app is daily work. Changing a client's template changes what every tech checks for that client, so only a handful of people get to do it.
  • Techs from our other tenants (the company has more than one Microsoft tenant) get added to the list as run-only the first time they sign in, never as admins. That's in the audit log, and a manager can switch them off.

The token itself

  • The portal never holds a long-lived key to the repo. It holds a GitHub App's private key, kept in the host's secret store, and uses it to ask GitHub for a fresh token each time someone clicks the button.
  • Each token is about as narrow as GitHub allows: one repository, file contents only, read or write, and GitHub kills it after one hour.
  • Write tokens are single-use in practice. After a template save, the app revokes the token straight away, then tries it again to make sure GitHub really does refuse it.
  • Everything goes in the audit log: every token issued, every token GitHub refused, who asked and when. The token itself never does.

What it can't do (yet)

  • Removing someone isn't instant. Taking a tech off the list stops them getting new tokens, but one they already have keeps working until its hour is up. For a read token, that's at most an hour of being able to download the app.
  • There is a big red button. Uninstalling the GitHub App, or deleting its key, kills every token at once.
  • The token gets you the app, not the client. AdminRunbook still runs as whoever's signed in on that server, so it can only do what that tech's own admin account could do anyway. The portal decides who gets the tool, and AD still decides what the tool can touch.

One-click updates use the same token: Check for updates pulls the newest version and restarts into it, so nobody ends up running something from three weeks ago.

What it does now

  • Onboard and offboard reviews in batches. Paste a list of users, run the checks, and get a colored table against that client's template. Double-click anyone for the details.
  • User details. Edit names, job title, department, company and manager, fix group membership (with an Add missing button for the template's groups), and run the offboarding actions one at a time. It also shows legacy per-user MFA and can enforce it in one click.
  • Microsoft 365, the right tenant only. Connect M365 signs in to the tenant that owns the template's domain, and refuses to check users anywhere else. Switch templates while connected to the wrong tenant and it warns you and offers to reconnect. It also works with a partner (GDAP) admin account.
  • Account sweeps. Security (privileged group members, Kerberos risks, passwords that never expire), hygiene (stale users and computers, people who never logged on, disabled accounts still in groups or the address list) and Microsoft 365 (no MFA method, forwarding outside the company), plus domain health checks. Long sweeps show results as they go and have a Stop button. Pick several and it builds one report with a page per sweep, ready to print or save as a PDF.
  • Copy for ticket. One click puts the checklist, the changes made this session and the user's current state on the clipboard as ticket notes.
Onboard review for five new hires: two done, one missing a printer group, one with name format problems, and one created in the default Users container and missing the sync group
Five new hires, checked against the client's template in one go.
The onboarding checklist for one new hire: eight checks ticked, with the e-mail format and display name format crossed out and the expected values shown next to them
Open any one of them for the detail: here, the name and e-mail format checks.
Offboard review for three leavers: one done, one disabled but still in the staff OU with four groups left, and one still enabled with five groups left
Three leavers: one done right, one half done, one nobody's touched yet.
The Account sweeps page: buttons for account, security, hygiene and Microsoft 365 sweeps, and the Kerberos risks sweep finding a scanner account with no pre-authentication and a service account with an SPN
The Kerberos risks sweep finding the two service accounts I planted in the lab.

Stuff that broke (again)

  • The sign-in library clash came back. Same Graph versus Exchange Online fight as before. This time the fix was loading Graph first, and if it still happens, the app offers to restart itself.
  • Exchange sign-in hung forever. Its own sign-in prompt could sit there and never finish. Now the app runs the browser sign-in itself and hands the token to Exchange Online.
  • Copy for ticket failed over remote sessions. The remote-control tool was holding the clipboard. Now it retries.
  • Lists arrived as one long item. Groups, licenses and aliases from Microsoft 365 were coming back joined into one string. Fixed.
  • Run checks didn't work for exactly one user. The same PowerShell single-result habit as last time. Some bugs follow you.
  • Failed actions counted as done. Not great in a tool whose whole point is checking that things are done. Now a failure is a failure, and an error in one button logs itself instead of closing the app.

What's next

  • Scrubbing contact details at offboarding. It's the step that still gets missed, and the tool doesn't check it yet.
  • Hooking it up to the request forms in my client portal, so a new-hire request turns straight into a review the tech can run.

← Back to the work

Looking for someone who does this for fun, too?