How to Force Reset GSuite Users' Passwords with Apps Script


Learn how the GSuite admin can change the Google account passwords of multiple users in their organization automatically with Google Apps Script.

Published in: Google Apps Script - GSuite - Password

You can use Google Apps Script to automatically reset the password of users in your GSuite domain. This script can only be executed under the Suite admin account. You also need to enable the AdminDirectory Advanced Service in your Apps Script Editor.

You can force reset passwords of members of a particular group in your organization or specify a list of email addresses and the Google Script will use the AdminDirectory service to change the password of specified users.

const getGroupMembers_ = groupEmail => {
  var emails = [];
  var pageToken;
  do {
    const { members = [], nextPageToken } = AdminDirectory.Members.list(
        maxResults: 200,
        pageToken: pageToken
    members.forEach(member => {
      if (member.status === "ACTIVE") {
    pageToken = nextPageToken;
  } while (pageToken);
  return emails;

const sendEmail_ = (emailAddress, password) => {
    to: emailAddress,
    cc: "",
    subject: `Password changed for ${emailAddress}`,
    body: `The GSuite admin has changed your Gmail password to ${password}`

const changePassword_ = emailAddress => {
  const temporaryPassword = Utilities.getUuid();
      password: temporaryPassword,
      changePasswordAtNextLogin: true
  sendEmail_(emailAddress, temporaryPassword);

const resetUserPasswordsForGroup = () => {
  const groupEmail = “”;
  const members = getGroupMembers_(groupEmail);
  members.forEach(member => changePassword_(member));

const resetGSuitePasswordForUsers = () => {
  const members = [
  members.forEach(member => changePassword_(member));

Change GSuite Passwords Periodically

You can create a time-based trigger in Google Scripts to automatically run the reset function at specific intervals (like update password on the first of every month).


The Google Script is written in ES6 with V8 runtime. If V8 is not enabled for your GSuite account, replace the manifest appsscript.json file with this:

  "timeZone": "Asia/Kolkata",
  "dependencies": {
    "enabledAdvancedServices": [{
      "userSymbol": "AdminDirectory",
      "serviceId": "admin",
      "version": "directory_v1"
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"

Enable Admin Directory Service

To use the Advanced Directory advanced Google service inside your Google Apps Script project, follow these instructions:

  • Open the Google Script, select the Resources menu and then choose Advanced Google services.
  • In the Advanced Google Service dialog that appears, toggle on/off switch next to the Admin Directory service
  • Click OK to save your changes.
📮  Subscribe to our Email Newsletter for Google tips and tutorials!
Published in: Google Apps Script - GSuite - Password

Looking for something? Find here!

Meet the Author

Web Geek, Google Developer Expert
Amit Agarwal

Amit Agarwal is a Google Developer Expert in Google Workspace and Google Apps Script. He holds an engineering degree in Computer Science (I.I.T.) and is the first professional blogger in India. He is the developer of Mail Merge for Gmail and Document Studio. Read more on Lifehacker and YourStory

Get in touch

Google Add-ons

Do more with your Gmail and GSuite account

We build bespoke solutions that use the capabilities and the features of Google Workspace for automating business processes and driving work productivity.

  1. Mail Merge with Attachments
    Send personalized email to your Google Contact with a Google Sheet and Gmail
  2. Save Emails and Attachments
    Download email messages and file attachments from Gmail to your Google Drive
  3. Google Forms Email Notifications
    Send email notifications to multiple people when a new Google Form is submitted
  4. Document Studio
    Create beautiful pixel perfect documents merging data from Google Sheets and Google Forms
  5. Creator Studio for Google Slides
    Turn your Google Slides presentations into animated GIFs and videos for uploading to YouTube