How to Automate Google Workspace Offboarding with Apps Script

Published: September 2025 · Author: GWS Automate

When an employee leaves, IT admins must secure their Google Workspace account quickly. Delays can mean lingering access to email, documents, and company data. In this post, I’ll walk through how to automate Workspace offboarding with Apps Script to reduce errors and save hours.

The Problem with Manual Offboarding

Manual offboarding often looks like a checklist:

When rushed, steps get skipped — creating security risks and lost data.

Why Automate Offboarding

Automation ensures every step happens the same way, every time. By using Google Apps Script with the Admin SDK, IT admins can:

Step-by-Step Guide

1. Suspend the User

function suspendUser(userKey) {
  var user = { suspended: true };
  AdminDirectory.Users.update(user, userKey);
}
  

2. Transfer Google Drive Files

function transferDrive(oldUser, newOwner) {
  AdminDirectory.Files.insert({
    oldOwnerUserEmail: oldUser,
    newOwnerUserEmail: newOwner
  });
}
  

3. Set Email Forwarding

function setForwarding(userKey, forwardTo) {
  Gmail.Users.Settings.ForwardingAddresses.create(
    { forwardingEmail: forwardTo },
    userKey
  );
}
  

4. Add Auto-Reply

Set a vacation responder letting contacts know the employee has left and who to reach instead.

5. Remove Group Memberships

Loop through groups and remove the user automatically.

Real-World Results

With automation, offboarding went from a 25-minute checklist to a single script execution. IT admins save hours weekly and reduce the chance of sensitive accounts being left active.

Common Issues & Fixes

Conclusion

Manual offboarding creates risk. Automating it with Apps Script ensures consistency, security, and peace of mind. Combined with onboarding automation, IT admins can save 10+ hours per week.

Next step: Want prebuilt scripts and templates for onboarding & offboarding? Check out our Starter Pack or Pro Pack.

← Back to Home