What It Does
This script changes nothing until you set DryRun=false and Approve=invoke-ad-offboarding. It refuses to run when the plan is more than MaxChanges, 25 by default, separate changes; each group removal counts as one. Look at the dry-run list first.
For the user in AccountName, the script disables an enabled account and resets the password to a random value if the account was enabled or its description was not already stamped. It removes direct groups other than Domain Users. It leaves the primary group alone. It stamps the description, can move the account to DisabledOu, and can hide it from address lists when requested and the Exchange attribute exists. LogOffSessions can sign the user out of sessions on this computer.
Before any change it saves a CSV with the original location, description, enabled state and memberships planned for removal. It warns when the primary group is something other than Domain Users and leaves it in place. The account is never deleted. Built-in and critical system accounts are refused.
The script does not handle Microsoft 365 licenses, mailboxes, cloud sign-in sessions, directory sync, or sessions on other servers. If none of the requested steps is needed, it reports Already offboarded. After a real run it checks the directory changes and reports failures. It needs rights to change AD users and group memberships.
Before You Run It
- Run it as a dry run first and read every change it lists, including each group.
- Set DisabledOu to a holding OU that already exists. The script never creates it.
- Do the Microsoft 365 or Entra ID offboarding separately, and run a directory sync if you use one.
- Confirm you have the right user. Use the exact sign-in name, DOMAIN\name or UPN.
- Keep the saved CSV. It is how you put the group memberships back.
Type and Risk
- Type: Action. It makes its change, checks the change worked and says what changed. It exits 0, or 2 when it could not do the job.
- Risk: High. It is a dry run unless you set both DryRun=false and Approve=invoke-ad-offboarding, and it stops before making more than 25 changes in one run unless you raise MaxChanges. Run it once as a dry run and read the list first.
- What it changes: Disables the user, resets the password, removes group memberships (saved first), stamps the description, moves the account, hides it from address lists and logs off its sessions on this computer.
- Restart: It never restarts the machine.
- Typical run: Under 30 seconds.
- Example answer: "Offboarded jsmith: disabled, password reset, removed from 4 group(s), description stamped, moved to OU=Disabled Users,DC=contoso,DC=com"
- Tested before listing on a Windows Server 2025 domain controller (VM) with Windows PowerShell 5.1, run as SYSTEM, against its own test cases.
Inputs
Pass an input as an argument (-Name value), as an environment variable with the same name, which is how most RMMs pass script variables, or change its default in the param() block at the top of the script. An argument wins over an environment variable, which wins over the default.
- AccountName: The user to offboard: the sign-in name (jsmith), DOMAIN\jsmith, or the user principal name. Required. (Named AccountName, not UserName: Windows already has an environment variable called USERNAME, which the runtime would read.)
- DisabledOu: The OU or container to move the account to, as a distinguished name, e.g. "OU=Disabled Users,DC=contoso,DC=com". Default empty: the account is not moved. When set, it must exist; the script never creates it.
- HideFromAddressLists: Hide the user from address lists when the directory has the msExchHideFromAddressLists attribute. true or false. Default true.
- LogOffSessions: Log the user off any session on this computer. true or false. Default true.
Every script also takes DryRun, OutputFormat (Text, Answer, Json or Csv), ExportPath and ResultField, which writes the answer to an RMM custom field.
License
Provided "as is" under the MIT License, without warranty of any kind. Test before production use. MSP Outpost and User First Digital Inc. accept no liability for any damage or loss.