Google Workspace User Offboarding Script

47 views
Skip to first unread message

Dawn Cestroni

unread,
Jun 29, 2026, 3:41:02 PMJun 29
to GAM for Google Workspace
Wondering if I'm close to running this script, would anyone be available to look at this script to see if I'm on the right path?



param(
   [Parameter(Mandatory=$true)]
   [string]$UserEmail,

   [Parameter(Mandatory=$true)]
   [string]$ManagerEmail
)

# Log file
$LogFile = "C:\Logs\Offboarding_$(Get-Date -Format yyyyMMdd).log"

function Write-Log {
   param([string]$Message)

   $TimeStamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
   "$TimeStamp - $Message" | Out-File -FilePath $LogFile -Append
   Write-Host $Message
}

Write-Log "Starting offboarding for $UserEmail"

try {

   # Suspend account
   Write-Log "Suspending account..."
   gam update user $UserEmail suspended on

   # Reset password
   Write-Log "Resetting password..."
   gam update user $UserEmail password random

   # Transfer Drive ownership
   Write-Log "Transferring Google Drive files..."
   gam create datatransfer olduser $UserEmail newuser $ManagerEmail application drive

   # Remove Google Workspace License
   Write-Log "Removing license..."
   gam update user $UserEmail license Google-Workspace-Business-Standard delete

   # Remove from all Google Groups
   Write-Log "Removing from groups..."
   gam user $UserEmail delete groups

   # Move to Inactive Users OU
   Write-Log "Moving account to Inactive Users OU..."
   gam update org "/Inactive Users" add users $UserEmail

   Write-Log "Offboarding completed successfully."

}
catch {
   Write-Log "ERROR: $_"
}

Dierk Polzin

unread,
Jun 29, 2026, 5:56:54 PMJun 29
to GAM for Google Workspace
I would add:

gam user <> collect orphans targetuserfoldername "Orphans - <>"
gam user <> delete photo
gam user <> deprov
gam user <> signout
gam update user <> archive ON
gam update user <> recoveryphone ""
gam update user <> recoveryemail ""

Maybe do something with teamdrives...  aka shared drives...
gam user <> print teamdrives 
gam delete drivefileacl <>  <>@lclark.edu

Jay Lee

unread,
Jun 29, 2026, 6:01:19 PMJun 29
to google-ap...@googlegroups.com
gam update user $UserEmail suspended on
gam update user $UserEmail password random
gam update org "/Inactive Users" add users $UserEmail

These three commands can be performed with a single command which will be faster and more efficient:
gam update user $UserEmail suspended on password random ou "/Inactive Users"

Jay Lee


--
You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/google-apps-manager/b3cde0c8-e474-4746-a28f-acda5298beddn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages