Library / Google Workspace

GWS-010 · Script

User Offboarding Automation

Runs a repeatable offboarding workflow for one or more departing Google Workspace users.

Version 1.0.0Language PowerShellUpdated November 2026

What it does

For each departing user, in this order: 1. Saves a list of the user's groups to the Reports folder (for your records) 2. Resets the password to a random value and signs the user out everywhere 3. Removes app passwords, backup codes and access tokens; turns off POP/IMAP 4. Hides the user from the directory (global address list) 5. Optionally sets an auto-reply and gives a manager delegated mailbox access 6. Transfers Drive files and calendars to the manager (or -TransferTo account) 7. Removes the user from all groups 8. Moves the user to the archive OU 9. Optionally removes a license 10. Suspends the account, unless an auto-reply or delegate is set (those need an active account); add -ForceSuspend to suspend anyway. Nothing is deleted. Preview mode (default) shows every step without making changes.

Requirements

GAM7, installed and authorized by you. GAM is not included. Windows PowerShell 5.1 or PowerShell 7.

How to run it

  • Run from: an admin workstation or scheduled task with GAM7 set up
  • This is an admin script for your Google Workspace tenant, not a per-device endpoint script
  • User interaction: none with app-only sign-in
  • Schedule: run on demand, or weekly for reports

Settings

NameWhat it doesOptionsDefault
ModePreview = show steps only (default). Apply = run them.Preview, ApplyPreview
UserOne departing user's email. Or use -InputCsv for several.
ManagerWho receives Drive files and calendars (and mailbox access, with -DelegateToManager).
InputCsvCSV with columns: Email, Manager.
ArchiveOrgUnitOU for departed users. Default: /Departed Users/Departed Users
AutoReplyMessageOptional auto-reply text. Example: "I am no longer with the organization. Please contact [email protected]."
DelegateToManagerGive the manager delegated access to the mailbox.False
RemoveLicenseSkuOptional license SKU ID to remove (for example 1010310008).
ForceSuspendSuspend even when an auto-reply or delegate is set.False
GamPathPath to GAM. Default: gam (on PATH).gam

Exit codes

  • 0 = Completed, all steps succeeded
  • 1 = Completed, but one or more steps failed (see log)
  • 2 = Script error (see log)

Testing steps

  1. Run it first with the mode set to Preview on one test account or small group. Nothing is changed in that mode.
  2. Read the log and confirm the planned changes are what you expect.
  3. Run your chosen settings on the same test target and confirm the result.
  4. Check the exit code: 0 = OK, 1 = needs attention, 2 = error (see log), 9 = this copy is past its Valid until date.
  5. Roll out to a small group next, then everyone.

Rollback steps

Preview mode changes nothing. The log records each step. Restore the account with GWS-002, add groups back from the log, and reassign the license. File transfers are not reversed automatically.

Version and change log

VersionDateChanges
1.0.0November 2026First release.