I have a project to send mail to multiple users, I have written script to send multiple users an Email using App script, but to make the mail more personalized, I want to start mail as "Hi Abhishek Mehta"
Using AdminDirectory.Users.get(userKey, {fields:'name'}) I am able to fetch the name of the users, but not sure how to list them in the sheet.
In normal words, I have 50 Email ids and want to fetch full name of the Email id and want to write it in a Google sheet using Google App Script.
Request help from the community.
name of getUser() returns an object, you'll need to access that object to get the first and surname of the user.
The following script will get all the users in your domain (provided you have admin access) sorted by email and list them in a sheet named Users
function listAllUsers() {
var ss = SpreadsheetApp.getActiveSheet();
var pageToken,
page;
var userInfo = []
do {
page = AdminDirectory.Users.list({
domain: '---------',
orderBy: 'email',
maxResults: 500,
pageToken: pageToken
});
var users = page.users;
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
try {
userInfo.push([user.primaryEmail, user.name.givenName, user.name.familyName]);
} catch (e) {
userInfo.push([user.primaryEmail, "", ""]);
}
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
var sheet = ss.getSheetByName('Users')
sheet.getRange(2, 1, userInfo.length, userInfo[0].length).setValues(userInfo);
}
To get the names of a list of users you can use the following script. It assumes that the usernames (email addresses) are listed in column A starting in row 2 and without breaks.
There are 3 values in the name object
.givenName is the users first name.
.familyName is the users surname
.fullName is the first name and surname separated by a space
function usersNames() {
var ss = SpreadsheetApp.getActiveSheet();
var data = ss.getRange('A2:A').getValues();
var userNames = [];
for (var i = 0; i < data.length; i++) {
if (data[i][0]) {
var names = AdminDirectory.Users.get(data[i][0]).name
userNames.push([names.givenName, names.familyName]);
} else {
break;
}
}
ss.getRange(2, 2, userNames.length, 2).setValues(userNames)
}
Here is the script for the same.
File id = Example in Bold Letters (https://docs.google.com/spreadsheets/d/1JeNKU366pzsdH-Pg9EsjKENLO0orqunduoOGJJMnKjM4/edit#gid=63023734)
File Name = Name of the sheet under the main spreadsheet, like sheet1 or sheet2
`function getUserName() {
var ss = SpreadsheetApp.openById("File ID");
var sheet = ss.getSheetByName("File Name")
var values = sheet.getDataRange().getValues()
var fileArray = [["User Name"]]
for(i=1; i <values.length; i++)
{
var userKey = values[i][2] // '2' = Cloumn C
try{
var status = "No Name Found"
var status = AdminDirectory.Users.get(userKey, {fields:'name'})
var fullname = status.name.fullName
Logger.log(fullname)
if (status != "No Name Found"){
status = fullname
}
}
catch (e) {
Logger.log(e.message)
var status = e.message
}
fileArray.push([status])
}
var range = sheet.getRange(1, 4, fileArray.length, 1).setValues(fileArray)
}`
Related
I'd like to allow a non admin user in our domain to be able to use a Google Sheet which is running code to:
List some groups in our organisation
Delete/Add users
This requires admin rights, so the following code will not run in a non-admin account... How is it possibile to authorise the non admin user to run admin code?
var RatatoskSheet = SpreadsheetApp.getActiveSpreadsheet();
// -- ADD USER TO GROUP -- Set trigger to onedit -- //
function addUsertoGroup(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() === 'AddUser') { //Hinders edits on other sheets
var userData = SpreadsheetApp.getActive().getSheetByName('AddUser');
var userEmail = userData.getRange(2, 1).getValue(); //Gets data from AddUser.A2
var groupId = userData.getRange(2, 2).getValue(); //Gets data from cell B2
var newMember = {
email: userEmail,
role: "MEMBER"
};
AdminDirectory.Members.insert(newMember, groupId); // Adds new member to a Google group
var groupData = SpreadsheetApp.getActive().getSheetByName('GroupAddress');
var groupTwo = [userEmail, groupId]
groupData.appendRow(groupTwo); //Add member and group to GroupAddress
var header = ['UserEmail', 'GroupID'];
userData.clear(); //Reset AddUser (Delete all)
userData.appendRow(header).setFrozenRows(1);
}
}
// -- REMOVE USER FROM GROUP -- Set trigger of this function to onedit -- //
function deleteGroupMember(e) {
var sheet = e.source.getActiveSheet();
if (sheet.getName() === 'RemoveUser') { //Hinders edits on other sheets
var RemoveUserData = SpreadsheetApp.getActive().getSheetByName('RemoveUser');
var groupData = SpreadsheetApp.getActive().getSheetByName('GroupAddress');
var userEmail = RemoveUserData.getRange(2, 1).getValue(); //Gets data from RemoveUser.A2
var groupId = RemoveUserData.getRange(2, 2).getValue(); //Gets data from RemoveUser.B2
AdminDirectory.Members.remove(groupId, userEmail); //Removes member from a Google group
var removeDataValues = RemoveUserData.getDataRange().getValues();
var groupDataValues = groupData.getDataRange().getValues();
var resultArray = [];
for (var n in groupDataValues) { //
var keep = true
for (var p in removeDataValues) {
if (groupDataValues[n][0] == removeDataValues[p][0] && groupDataValues[n][1] == removeDataValues[p][1]) {
keep = false;
break;
}
}
if (keep) {
resultArray.push(groupDataValues[n])
};
}
var start = 2; //Starts from Row 2 //
var killTheRows = groupData.getLastRow() - start + 1; // // These lines deletes all rows in GroupAddress
groupData.deleteRows(start, killTheRows); //Delete all rows with values//
groupData.getRange(2, 1, resultArray.length, resultArray[0].length).setValues(resultArray); //Repopulate the rows in GroupAddress
var header = ['UserEmail', 'GroupID'];
RemoveUserData.clear();
RemoveUserData.appendRow(header).setFrozenRows(1);
}
}
// -- LISTS ALL GROUPS AND USERS WITHIN THEM -- Set this as a timed trigger to error correct once a day -- //
function listAllGroups() {
var grouprows = [];
var pageToken;
var page;
do {
page = AdminDirectory.Groups.list({
domain: 'THEDOMAIN',
maxResults: 200,
pageToken: pageToken
});
var groups = page.groups;
if (groups) {
for (var i = 0; i < groups.length; i++) {
var group = groups[i];
if (group.email.substring(0, 5) === "staff") {
grouprows.push(group.email);
}
}
}
pageToken = page.nextPageToken;
} while (pageToken);
var rows = [];
var pageToken, page2;
for (var j = 0; j < grouprows.length; j++) {
do {
page2 = AdminDirectory.Members.list(grouprows[j], {
domainName: 'YOURDOMAIN',
maxResults: 500,
pageToken: pageToken,
});
var members = page2.members;
if (members) {
for (var i = 0; i < members.length; i++) {
var member = members[i];
var row = [member.email, grouprows[j]];
rows.push(row);
}
}
pageToken = page2.nextPageToken;
} while (pageToken);
if (rows.length > 1) {
var groupData = RatatoskSheet.getSheetByName("GroupAddress");
var header = ['UserEmail', 'GroupID'];
groupData.clear();
groupData.appendRow(header).setFrozenRows(1);
groupData.getRange(2, 1, rows.length, header.length).setValues(rows);
}
}
groupData.deleteRow(2); //NB! Removes first group(all#yourdomain.com) Make this whole line a comment if unsure.
}
A way to achieve this is by creating a service account and using domain wide delegation of authority.
After that, since you want to continue on using Apps Script, you will have to get the access token for this service account and make the request using UrlFetchApp since you cannot pass an access token while making a request using Admin SDK Directory advanced service.
Therefore, the requests will end up looking something similar to:
var options = {
method: "GET",
contentType: "application/json",
muteHttpExceptions: true,
};
var response = UrlFetchApp.fetch('https://admin.googleapis.com/admin/directory/v1/groups/{groupKey}/members', {
headers: {
Authorization: 'Bearer ' + token
}
});
However, this approach might depend on the restrictions you have set in place for your account.
Another option is to deploy your script as a web app
For deploying a web app, the script should contain a doGet(e) or a doPost(e) and return a HTML service HtmlOutput object or a Content service TextOutput object.
After doing this, you should deploy the web app with the following settings:
Execute as: Me
Who has access: Anyone within domain
Reference
Service accounts;
Delegate domain-wide authority to your service account;
Apps Script Web Apps.
I am trying to retrieve the mobile device report but I keep getting this error: "API call to directory.mobiledevices.list failed with error: Bad Request".
I think the issue is the customerId. What should I use to retrieve all mobile devices info? I have tried using "all" and also defining the domain name but no luck.
Must appreciated for your time and input! TIA!
function mobileReport() {
var spreadsheet = SpreadsheetApp.getActive();
var sheet = spreadsheet.getSheetByName('SHEETNAME');
sheet.clear();
// Append the headers.
var headers = ['Full Name','Email','Device Id','Model','Type','Status','Last Sync'];
sheet.appendRow(headers).setFrozenRows(1);
var rows = [];
var pageToken;
var count = 0;
do {
var page = AdminDirectory.Mobiledevices.list({
orderBy: 'email',
maxResults: 500,
pageToken: pageToken
});
var users = page.mobiledevices;
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
rows.push([user.name,user.email,user.deviceId,user.model,user.type,user.status,user.lastSync]);
}
// Append the results.
sheet.getRange(2, 1, rows.length,headers.length).setValues(rows);
}
else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
}
Modification points:
When I saw the official document, it seems that at the method of "Method: mobiledevices.list" in Directory API, customerId is required to be used as follows.
customerId: The unique ID for the customer's Google Workspace account. As an account administrator, you can also use the my_customer alias to represent your account's customerId. The customerId is also returned as part of the Users resource.
But in your script, this is not used. By this, the arguments for AdminDirectory.Mobiledevices.list are not correct. I think that this is the reason of your issue of "Bad Request".
The maximum value of maxResults is 100.
It seems that the email of Enum of orderBy is EMAIL. Ref
In your script, setValues is used in the loop and the same range is used. In this case, the values are overwritten by every loop.
When above points are reflected to your script, it becomes as follows.
Modified script:
Please modify your script as follows.
From:
var rows = [];
var pageToken;
var count = 0;
do {
var page = AdminDirectory.Mobiledevices.list({
orderBy: 'email',
maxResults: 500,
pageToken: pageToken
});
var users = page.mobiledevices;
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
rows.push([user.name,user.email,user.deviceId,user.model,user.type,user.status,user.lastSync]);
}
// Append the results.
sheet.getRange(2, 1, rows.length,headers.length).setValues(rows);
}
else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
To:
var customerId = "###"; // <--- Please set customerId.
var rows = [];
var pageToken;
var count = 0; // It seems that this variable is not used in the script.
do {
var page = AdminDirectory.Mobiledevices.list(customerId, {
orderBy: 'EMAIL',
maxResults: 100,
pageToken: pageToken
});
var users = page.mobiledevices;
if (users.length > 0) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
rows.push([user.name, user.email, user.deviceId, user.model, user.type, user.status, user.lastSync]);
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
if (rows.length > 0) {
sheet.getRange(2, 1, rows.length, headers.length).setValues(rows);
}
Note:
In this modified script, it supposes that you can retrieve the values using AdminDirectory.Mobiledevices.list. Please be careful this.
Reference:
Method: mobiledevices.list
I have this code. I set a time trigger to retrieve every employee's names, email address from the email domain, assign a primary key to it and write it on spreadsheet. I did that for attendance system. But when the execution time is greater than 5 minutes, I can't retrieve the whole employees name and email address from the email domain.
What can I do?
Please help.
Thank you!
function primarykeyrecord(){
var lastval;
var sheet=getData();
var data = sheet.getDataRange().getValues();
lastval=data[data.length-1][0];
if(lastval !== "primarykeyvalue"){
lastval=lastval+1;
}
else {
lastval=1;
}
// Logger.log( lastval);
return lastval;
}
// list all the user from the domain
function listAllUsers() {
var pageToken, page;
var today =methodtimenow();
do {
page = AdminDirectory.Users.list({
domain: '',
//orderBy: 'givenName',
maxResults: 300,
pageToken: pageToken
});
users = page.users;
userslength=users.length; // the number of user from the email domain
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
var sheet = getData();
var lastval=primarykeyrecord();
var range = sheet.getRange(sheet.getLastRow()+1, 1, 1, 4);
var values = [[lastval,today,user.primaryEmail,user.name.fullName ]];
range.setValues(values);
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
//Logger.log(values);
}
The reason your script is timing out is, you are recursively calling setValues() and getValue(). Both are resource intensive process and should be used sparingly as possible, use batch updating instead.
The below code gets all the user data in values array and adds the array in one go at the end.
function listAllUsers() {
var pageToken, page;
var today =methodtimenow();
var lastval=primarykeyrecord(); //Access the last value once and then keep adding one
var values = [] //Create empty array
do {
page = AdminDirectory.Users.list({
domain: '',
//orderBy: 'givenName',
maxResults: 300,
pageToken: pageToken
});
users = page.users;
userslength=users.length; // the number of user from the email domain
if (users) {
// And all the user data to values array
for (var i = 0; i < users.length; i++) {
var user = users[i];
var temp = [lastval,today,user.primaryEmail,user.name.fullName ];
values.push(temp)
lastval++; //Increase key value by one
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
var sheet = getData();
var lastRow = sheet.getLastRow()
var range = sheet.getRange(lastRow+1, 1, values.length, 4);
range.setValues(values);
//Logger.log(values);
}
Hope that helps!
I created a script to write the list of users in an OU to a spreadsheet and this works well. However now I wanted to script to write data for multiple OU's into the same spreadsheet but the '&&' operator does not seem to work. I tried using the OR '||" operator but that does not seem to work either. Any ideas?
function listAllUserRR() {
var sh = '1Or1yr9JtwsEvg97U1VjX4XNEZylxoVPwRzJXC6wZDKx';
var sheet = SpreadsheetApp.openById(sh);
var sheet1 = sheet.getSheetByName('Google Users');
var sheet1range = sheet.getRange("A:F")
sheet1range.clear()
var data = [];// array to store values
data.push(['Email' ,'Firstname', 'Lastname', 'OU', 'Suspended', 'LastLoginTime']);// store headers
var pageToken, page;
do {
page = AdminDirectory.Users.list({
customer: 'C00ont7ej',
query: "OrgUnitPath='/Brazil'" || "orgUnitPath='/Argentina'",
pageToken: pageToken
});
var users = page.users;
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
data.push([user.primaryEmail, user.name.givenName, user.name.familyName, user.orgUnitPath, user.suspended, user.lastLoginTime, ]);//store in an array of arrays (one for each row)
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
sheet1.getRange(1,1,data.length,data[0].length).setValues(data);
var dated = sheet.getRange("P1")
dated.setValue(Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'dd-MMM-yyy'));
}
This line is wrong:
query: "OrgUnitPath='/Brazil'" || "orgUnitPath='/Argentina'",
because you use a javascript operator between two strings. Javascript will do:
if the first string is not falsey (not 0, null, undefined, false or empty), it will return the first string. Or if not, it will return the second string. Example:
var query = "OrgUnitPath='/Brazil'" || "orgUnitPath='/Argentina'";
console.log(query);
// Prints: OrgUnitPath='/Brazil'
var query = "" || "orgUnitPath='/Argentina'";
console.log(query);
// Prints: orgUnitPath='/Argentina'
This is definately not what you want. You just want something like this:
var query = "OrgUnitPath='/Brazil' OR orgUnitPath='/Argentina'";
console.log(query);
// Prints: OrgUnitPath='/Brazil' OR orgUnitPath='/Argentina'
Also notice that you are using orgUnitPathand OrgUnitPath (both uppercase and lowercase o). I don't know if the query is case sensitive, but it is good to be consistent anyways...
I don't see any indication that the Directory API lets you specify multiple OUs when searching for users:
https://developers.google.com/admin-sdk/directory/v1/guides/search-users
Why not just split out the AdminDirectory lookup as a function that takes the OU name and the array and call it from a loop that passes each OU that you want and the array and then you can dump it all back into the spreadsheet.
function listAllUserRR() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.insertSheet(Utilities.formatDate(new Date(),Session.getScriptTimeZone(),'dd-MMM-yyy_HH:mm'));
var data = [];// array to store values
data.push(['Email' ,'Firstname', 'Lastname', 'OU', 'Suspended', 'LastLoginTime']);// store headers
var orgUnitsArray = ["OrgUnitPath='/Brazil'", "orgUnitPath='/Argentina'"];
for (var i=0; i < orgUnitsArray.length; i++) {
getOrgUnitUsers(orgUnitsArray[i], data)
}
sheet.getRange(1,1,data.length,data[0].length).setValues(data);
}
function getOrgUnitUsers(orgUnit, userArray) {
var pageToken, page;
do {
page = AdminDirectory.Users.list({
customer: 'my_customer',
query: orgUnit,
pageToken: pageToken
});
var users = page.users;
if (users) {
for (var i = 0; i < users.length; i++) {
var user = users[i];
userArray.push([user.primaryEmail, user.name.givenName, user.name.familyName, user.orgUnitPath, user.suspended, user.lastLoginTime, ]);//store in an array of arrays (one for each row)
}
} else {
Logger.log('No users found.');
}
pageToken = page.nextPageToken;
} while (pageToken);
}
G'day,
I have several Google Groups under a Google Apps account that my nonprofit uses. Some of these groups are quite large and managing their membership with the web UI is pretty awful.
I'm hoping someone can help me come up with a script that can synchronize a list that I maintain on a Google Docs Spreadsheet with a Group so that when I remove someone from the sheet, they get removed from the group -- and when someone gets added to the sheet, they get added to the group.
I was taking a look at the Directory API but I'm not savvy enough to figure out how to build a script for what I need. Side note, I did play around with a different script someone posted here that uses similar API methods, and I got that particular script to work -- so in other words, my account is now properly set up for API access.
Perhaps the easiest way to do this programmatically would be to delete the group's membership entirely, then add each member again, each time the script runs?
Thank you in advance for your assistance.
Here are several functions that you can use to accomplish what you would like.
First here is the removal process. As commented by Sandy, create a column that you will use to mark members for removal. You should be able use what ever you like here as long as the ones not being deleted are blank. You will need to change the variable "marked" to reflect that columns number, you will also need to do the same for the "email" variable. That being the column that holds the users emails.
Make a copy of your sheet first and make sure that when the rows are deleted that they are the correct ones!
/**
*Removes members from group that are marked for removal in a specific column
*/
function removeMarkedMembers() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var range = sheet.getDataRange();
var data = range.getValues();
//Adjust these following variables to match your sheet
var groupEmail = 'group#email.com';//change to your group email address
var marked = 7;//number of column used to mark for removal ex. Column A = 1
var email = 4; //number of column that holds member email address.
//must adjust columns numbers to zero based array integers
marked = marked-1;
email = email-1;
var rows = [];
for (var d in data) {
var rowData = data[d];
if(rowData[marked] != "" || rowData != null) {
removeGroupMember(groupEmail, rowData[email]);
rows.push(new Number(d)+1)
}
}
for (var r in rows) {
sheet.deleteRow(rows[r])
}
}
function removeGroupMember(groupEmail, userEmail) {
userEmail = userEmail.trim();
AdminDirectory.Members.remove(groupEmail, userEmail);
}
Lastly here are some other functions for managing groups, use them as needed. Probably best to create a menu that you can just call these from inside the spreadsheet.
/**
*Adds all email addresses in column to group.
*/
function addAllToGroup() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var row = sheet.getLastRow();
var column = 7;
var range = sheet.getRange(2, column, sheet.getLastRow(), 1)
var emails = range.getValues();
for (var e in emails) {
var email = emails[e]
if(validateEmail(email)) {
addGroupMember(email, 'your#groupemailaddress.com');////Must replace with group email address you want them added too.
}
}
}
function addGroupMember(userEmail, groupEmail) {
var member = {
email: userEmail,
role: 'MEMBER'
};
AdminDirectory.Members.insert(member, groupEmail);
}
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
/**
*Removes all members from a defined group
*/
function removeAllMembers() {
var groupEmail = 'group#email.com';
var members = AdminDirectory.Members.list(groupEmail).members;
for (var m in members) {
var member = members[m];
var email = member.email;
removeGroupMember(groupEmail, email);
}
}
This should help you get a nice finished product.
Edited Code to handle reported errors in the comments.
Also updated the marked column must use an "x" for marker to be removed.
Lastly to properly handle the deletion of the row, you need to clear it and then sort the entire sheet or your will get wrong rows removed. Remember to adjust to your parameters.
/**
*Removes members from group that are marked for removal in a specific column
*/
function removeMarkedMembers() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var range = sheet.getRange(2, 1, sheet.getLastRow()-1, sheet.getLastColumn());
var data = range.getValues();
Logger.log(data)
//Adjust these following variables to match your sheet
var groupEmail = 'test-group#email.com';//change to your group email address
var marked = 2;//number of column used to mark for removal ex. Column A = 1
var email = 1; //number of column that holds member email address.
//must adjust columns numbers to zero based array integers.
marked = marked-1;
email = email-1;
Logger.log(marked+' : '+email)
var rows = [];
for (var d in data) {
var rowData = data[d];
if(validateEmail(rowData[email]) && rowData[marked] == "x") {
Logger.log('marked')
removeGroupMember(groupEmail, rowData[email]);
rows.push(new Number(d)+2)
}
}
for (var r in rows) {
var row = rows[r];
sheet.getRange(row, 1, 1, sheet.getLastColumn()).clear();
}
range.sort(1);
}
function removeGroupMember(groupEmail, userEmail) {
Logger.log(userEmail)
userEmail = userEmail.trim();
AdminDirectory.Members.remove(groupEmail, userEmail);
}
/**
*Adds all email addresses in column to group.
*/
function addAllToGroup() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName('Sheet1');
var row = sheet.getLastRow();
var column = 1;
var range = sheet.getRange(2, column, sheet.getLastRow(), 1)
var emails = range.getValues();
for (var e in emails) {
var email = emails[e]
if(validateEmail(email)) {
addGroupMember(email, 'test-group#email.com');////Must replace with group email address you want them added too.
}
}
}
function addGroupMember(userEmail, groupEmail) {
var member = {
email: userEmail,
role: 'MEMBER'
};
var members = AdminDirectory.Members.list(groupEmail).members
for (var m in members) {
if(members[m].email == userEmail) {
return 'Member already exist';
}
}
AdminDirectory.Members.insert(member, groupEmail);
}
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s#\"]+(\.[^<>()[\]\\.,;:\s#\"]+)*)|(\".+\"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
/**
*Removes all members from a defined group
*/
function removeAllMembers() {
var groupEmail = 'test-group#email.com';
var members = AdminDirectory.Members.list(groupEmail).members;
for (var m in members) {
var member = members[m];
var email = member.email;
removeGroupMember(groupEmail, email);
}
}