This script automates the process of moving suspended user accounts to a specific Organizational Unit (OU) named "Suspended Users" in a Google Workspace domain. If the target OU does not exist, the script creates it.
- Automatically fetches the customer ID of the authenticated admin account using "my_customer".
- Retrieves a list of all suspended users in the domain.
- Checks if the target OU exists; if not, it creates the OU.
- Moves all suspended users to the "Suspended Users" OU.
- Logs all operations in a Google Sheet named "Logs".
- Copy the Google Sheet file and open the copy.
- Reload the Google Sheet, and you should see a new menu named `Script Menu` with the option to run the script manually.
- Manually create it in your Admin console, at the root or under another parent OU. *
- This script does not create the OU; it only uses it.
- Time-based triggers allow the script to run automatically at set intervals.
- Steps to configure the trigger:
a. Open the Apps Script editor from the Google Sheet (`Extensions > Apps Script`).
b. In the Apps Script editor, click on the **clock icon** in the left-hand toolbar (Triggers).
c. Click the blue "Add Trigger" button at the bottom right.
d. In the "Add Trigger" dialog:
- Function to run: Select `moveSuspendedAccounts`.
- Deployment: Keep it as "Head".
- Event source: Choose "Time-driven".
- Type of time-based trigger: Select "Day timer", "Week timer", or any preferred interval.
- Select specific time (if applicable): Choose a time when the script should run.
e. Click "Save" to finalize the trigger.
You can run the script manually by selecting `Script Menu > Move Suspended Accounts` in the Google Sheet. Alternatively, let the time-based trigger automate the process.
- Suspended user accounts will be moved to the "/Suspended Users" OU.
- A log of actions (successes and errors) will be recorded in a sheet named "Logs".
- If the target OU does not exist, the script will create it and log the action.