I'm working on a script which consist in get members from a group, the script identifies if the mail whether is a group email or a member email, but, in my job, we have groups in groups !
So here's the script
function getGroupUsers() {
var group = sheet.getActiveRange().getValue();
var members = AdminDirectory.Members.list(group).members;
for (var i = 1; i < members.length; i++) {
var member = members[i];
var caseUser = sheet.getRange(i+1, 1);
var caseGroupe = sheet.getRange(i+1, 2);
var lastRange = sheet.getRange(sheet.getLastRow(), 3);
// var caseGroupe2 = sheet.getRange(i+1, 4);
switch (member.type) {
case 'USER':
Logger.log('%s is a user', member.email);
caseUser.setValue(member.email);
break;
case 'GROUP':
Logger.log('%s is a group', member.email);
//var group = GroupsApp.getGroupByEmail(member.email);
caseGroupe.setValue(member.email);
break;
default:
Logger.log('nothing');
}
That's workin, as groups going in the second column, but i need them to be auto extended , like what I'm doing with the loop in the begining, but I'm not sure how can it works, I tried loops in loops but when I get members of the group there's only one written in the case instead of all.
If you need more information, or you need me to explain a point you're not sure to understand just tell me