Created
December 29, 2016 10:55
-
-
Save denvers/a5b6e90a86056fb33274940206fcceee to your computer and use it in GitHub Desktop.
Force a password reset for G Suite (former Google Apps) users in a group. Also skip (some) user(s) if you want to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Periodic reset all user password in a Google Apps (G Suite) group. | |
* Optional: skip users based on emailaddress | |
* | |
* -- You need Google Apps (G Suite) admin rights to run this script. -- | |
* -- Use Google Apps script triggers to force resets periodically. -- | |
* | |
* @author: Denver Sessink <https://twitter.com/webvakker> | |
*/ | |
function periodicPasswordReset() { | |
try { | |
var SKIP_USERS = ['[email protected]']; | |
var GROUP_EMAIL = "[email protected]"; | |
// Get group by GROUP_EMAIL and fetch all users of this group | |
var group = GroupsApp.getGroupByEmail(GROUP_EMAIL); | |
var users = group.getUsers(); | |
for (var i = 0; i < users.length; i++) { | |
var user = users[i]; | |
var userEmail = user.getEmail(); | |
if ( SKIP_USERS.indexOf(userEmail) > -1 ) { | |
// Skip this user | |
Logger.log("Skipping: " + userEmail); | |
continue; | |
} | |
Logger.log("Forcing password reset for: " + userEmail); | |
// Change password at next login -> true and save! | |
var userObject = AdminDirectory.Users.get(userEmail); | |
userObject.changePasswordAtNextLogin = true; | |
AdminDirectory.Users.update(userObject, userEmail); | |
} | |
GmailApp.sendEmail( | |
Session.getEffectiveUser().getEmail(), | |
'Log for User Pass Change Script: Successful', | |
Logger.getLog() | |
); | |
} catch(e) { | |
Logger.log('--------------------------------------------------------'); | |
Logger.log('Error occured: '+e.message); | |
// Send an email to yourself with logs | |
GmailApp.sendEmail(Session.getEffectiveUser().getEmail(), 'Log for User Pass Change Script : Error occured', Logger.getLog()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a quickly thrown variation that would force-reset password for all users in the domain.