Share this Topic

Bulk reset Password G Suite Users using Directory API

How to Bulk reset Password G Suite Users using Directory API – As an administrator of a big G Suite account we will come to a point where we need to initiate a Bulk Reset Password for our Users. This is not a simple task if we will do it for 20+ users at the same time. This prompted us here in Hosting Noob to find a solution and help fellow G Suite admin in doing a Bulk reset Password G Suite Users using Directory API.

 




 

G Suite Directory API

Just a quick information about the Directory API lets you perform administrative operations on users, groups, organization units, and devices in your account. Some of its capabilities are below:

 

How to Bulk reset Password G Suite Users using Directory API

G Suite Directory API features

 

Bulk reset Password G Suite Users using Directory API guide

These are the step-by-step instructions on how to run a script that will automatically list all Groups within a domain and show their permissions.

Prerequisites:

  • User is logged-in to a Super Admin on the domain of the Google Group.
  • API access is enabled for the domain.

 




 

To create the Script:

        • Create a new Google Sheet via sheets.google.com, a blank sheet will do. Make sure to also add a custom name for the new Google Sheet.
        • Create the following columns on the new Sheet: Email,​ Password ​and Status
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        •  Once you’ve created a new Sheet, click Tools > Script Editor​.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        • A new Google Script window will open on a new tab. Please remove all the text under code.gs
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        • Copy the all the text from textbox ​below and paste in under Code.gs​ on the script.google.com ​window
          function onOpen(e) {

          var subMenu = [{name:”Run Script”, functionName: “main”}];

          SpreadsheetApp.getActiveSpreadsheet().addMenu(“Bulk Password Reset”, subMenu);

          }

          function main() {

          var initRow = 2;

          var email, password, result;

          var emailCol = 1, pwCol = 2,statusCol = 3;

          var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

          var range = sheet.getLastRow();

          // Validate the current OU for each user

          if( range > 1 ){

          sheet.getRange( 1, statusCol ).setValue(“Status”);

          for( var i = initRow; i <= range; i++ ){

          email = sheet.getRange( i, emailCol ).getValue();

          password = sheet.getRange( i, pwCol ).getValue();

          result = AdminDirectory.Users.update({“password” : password}, email);

          sheet.getRange( i, statusCol ).setValue(“Done Resetting!”);

          sheet.getRange( i, statusCol ).setBackground(“#00FF00”);

          }

          var ui = SpreadsheetApp.getUi();

          var response = ui.alert(“Operation Complete”,

          “Successfully reset ” + (range – 1) +” users!”, ui.ButtonSet.OK);

          }

          else{

          var ui = SpreadsheetApp.getUi();

          var response = ui.alert(“No users to reset”,

          “Nothing to validate, exiting process”, ui.ButtonSet.OK);

          }

          }




        1. Click on Resources ​> Advanced Google Services
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        2. A window will popup, kindly turn on AdminDirectory API ​by clicking the On/Off button on the upper right side, then click “Google Developers Console”​ on the same window.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        3. A new tab should open with the URL console.developers.google.com, click on Enable API.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        4. On the next page, search for “admin sdk”, and click the Admin SDK result.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        5. Click “Enable API​” on the next page
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        6. Go back to the Google Script tab and click ok to close the Advanced Google Services popup. Select “onOpen​” on the “Select​ Function​” dropdown, then hit the Play ​button.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           

        7. Fill out the sheets with the email and password values.
          How to Bulk reset Password G Suite Users using Directory API

          Bulk reset Password G Suite Users using Directory API Guide

           




      1. You will now see the “Bulk Password Rest​” menu item. Click it then select “Run​ Script​”.
        How to Bulk reset Password G Suite Users using Directory API

        Bulk reset Password G Suite Users using Directory API Guide

         

      2. If the script runs successfully, you should be able to see the Sheets filled out with information about the Groups within the domain and the permission for each of them.
        How to Bulk reset Password G Suite Users using Directory API

        Bulk reset Password G Suite Users using Directory API Guide

 Important Reminders

Hosting Noob guides and tutorials are written by experts but the accuracy and reliability of this still depends if you follow the guide correctly. We also want to point out that as of this writing it is still working with no errors on all G Suite editions but of course G Suite is continuously being developed and updated so it might not work once you tried it out.

We will appreciate if you can comment anything you want to say about this article including further development of guide. You can also tell us if it’s not working anymore so we can verify it in our end. Again thanks for visiting us here at Hosting Noob make sure to check us out every once in a while for other informative guide. Stay tuned!

 

Share this Topic