Teacher Tech blog with Alice Keeler

Paperless Is Not a Pedagogy

Alice Keeler

Bulk Removing Users From G Suite Admin

Bulk Remove G Suite Users

Bulk Removing Users From G Suite Admin

Bulk Remove G Suite Users

G Suite Admin – Bulk User Removal

I am the apps admin on my G Suite EDU domain. For a training I had created 100 temporary accounts and then wanted to delete them after the training. Doing a Google Search the results show me how to tediously remove one user at a time. Unacceptable. It took me probably longer to find how to use Google Apps Script to remove multiple users at once than it would have to just remove each individual user but I found some sample code on stack overflow and was able to quickly remove the users.

Download Users

After going to admin.google.com and clicking on Users I was able to click on “Download users.”

Download Users in Admin Panel

The default is to download only the 5 columns shown in the admin panel, and that is probably all I needed but I like seeing what all data it showed for each user. And OF COURSE I want to export it to a Google Sheets spreadsheet.
download user data to google sheets

Sort Spreadsheet

It is a beautiful thing to be able to sort a spreadsheet of user data. I sorted by “Last Sign In [READ ONLY]” to see who had never signed in or had signed in only yesterday. I deleted the rows that included myself and others on my domain who actually used their accounts yesterday. I also deleted the rows that are active but not used yesterday. Leaving me with a spreadsheet of data of users I wanted to delete. I ended up with 1654 users I wanted to delete. I renamed the tab to “neverloggedin.”

Google Apps Script

Going to script.google.com I wanted to code removing all 1654 users at once. I had used this nifty page from the Google Developers page to remove a few one at a time (but still faster than the admin panel), so my actual number was slightly lower. This is important because when I tried to run my script I got an error since some of the users I was trying to remove did not exist.

Authorize the API

Use the Resources menu to select “Advanced Google services.”

Resources Menu advanced google services

and enable the Admin Directory API.

Admin API

Write the Code

It’s ridiculous how easy this is to code and how hard it was to find how easy it was to code. Thanks to Stacks Overflow for the solution. After enabling the API for Admin directory you simply need AdminDirectory and press period to manage the users on your G Suite domain!

code for delete users

Link to script file

function deleteUsers() {
var ss = SpreadsheetApp.openById(’14g2QfLJkEGHhS1PNyasLQe_JlKP1a36tqhWjN4irFE’);//id of exported spreadsheet
var sheet = ss.getSheetByName(‘neverloggedin’);//tab name of data
var data = sheet.getDataRange().getValues();//all the data in an array

var len = data.length;//number of rows in the array

for(var i=1; i<len; i++){//has a header row, start counting at 1
var user = data[i][2];//3rd column has the user email addresses
Logger.log(user);

//use try catch in case a user is already removed
try{
AdminDirectory.Users.remove(user);
}
catch(err){}

}
}

 

 

 

 

5 Easy Steps for Teaching with Digital Tools

Introducing digital tools into your teaching can seem challenging at first. There are many tools out there, and it might feel like there’s a lot to learn. But with easy steps for teaching with digital tools, you can start simply and gradually. There’s no need to dive in all at once – just take it one step at a time. Taking easy steps for teaching with digital tools starts with trying something!

Read More »
Students Prepare to Present

Help Your Students Prepare to Present

Maximize student success in presentations with ‘Speaker Notes by AliceKeeler,’ the ideal Google Slides add-on. Enhance how students prepare to present with easy transfer of speaker notes to Google Docs, promoting effective communication skills. Dive into the world of engaging, technology-aided presentations and empower students to shine in their academic endeavors. Discover the key to transforming student presentations into interactive, skill-building experiences.

Read More »

Infographic 7 Basic Steps for a Google Form

New to using Google Forms? This tool is essential for teachers to not only save time but to be adaptive to student needs. Use Forms to survey students, play games, personalize instruction, and assessment. This infographic on the 7 basic steps for a Google Form will help you get started.

Read More »

Online Workshop: Get Your Add-on Published

How can you make Google Workspace (Docs/Sheets/Slides) even better? You can create custom Add-ons with Google Apps Script. Wondering How to Get Your Google Workspace Add-on Published? Join Alice Keeler, Google Developer Expert, to learn the steps to get your Add-on officially published.

Read More »

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d