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.
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