Skip to content

Instantly share code, notes, and snippets.

@hinklefoxmail hinklefoxmail/reset.gs Secret
Created Sep 3, 2017

Embed
What would you like to do?
Auto Password Reset Gmail
function resetPassword() {
var ss = SpreadsheetApp.getActive();
var cell = ss.getSheetByName('counter').getRange(1, 1)
var counter = cell.getValue();
cell.setValue(counter+1);
var data = ss.getSheetByName('Emails').getDataRange().getValues()
if (counter % 6 === 0){
for (var i = 0; i < data.length; i++){
var email = data[i][0];
Logger.log(email);
try{
var user = AdminDirectory.Users.get(email);
user.changePasswordAtNextLogin = true;
var response = AdminDirectory.Users.update(user, email);
Logger.log('success');
}
catch(e){
Logger.log('fail');
Logger.log(e);
}
}
} else {
Logger.log(counter)
}
}
function emailReminder(){
var ss = SpreadsheetApp.getActive();
var cell = ss.getSheetByName('counter').getRange(1, 1)
var counter = cell.getValue();
var data = ss.getSheetByName('Emails').getDataRange().getValues()
if (counter % 6 === 0){
for (var i = 0; i < data.length; i++){
var email = data[i][0];
Logger.log(email);
MailApp.sendEmail(email, 'Password Reset on Monday', 'Just a reminder that on Monday you will need to change your Gmail password. The system will automatically ask you to do this. No action is currently required by you.');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.