0

First post ever, Looking to get some help here. I'm trying to run a daily job using googles apps scripts. I essentially want to export all groups within my google apps/suite domain (im a super admin) and list the users within them then have that data imported into a google sheet. Here's what I have so far. The documentation gives me a headache. Any help would be appreciated.

I've already done the initial steps to authorize

function readgroupsandusers() {
  var pageToken, page;
  do {

//Pulls down Admin SDK API that allows auth.
    page = AdminDirectory.Groups.list({
      domain: 'example@.com',

//Show max result of 500.
      maxResults: 500,
      pageToken: pageToken
    });

//Presents group name + group email address.
    var groups = page.groups;
    if (groups) {
      for (var i = 0; i < groups.length; i++) {
        var group = groups[i];     
        Logger.log('%s (%s)', group.name, group.email);
        var users 
//I know something is suppose to go here...
      }

    }
    else 

//If it doesn't find anything present this message.
    {     
      Logger.log('No Groups in this domain exist.');
    }
    pageToken = page.nextPageToken;
  } while (pageToken);
}
Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • What's happening when you run this? Is the script in a spreadsheet? More information about what's happening would be helpful. – Brian Apr 28 '17 at 01:18
  • @BrianBennett HI! - When I run the above I get a list of all groups within my domain. The script currently is running behind google app scripts. I'm stuck at trying to extract each user within each of their respective groups. – Tommy Nguyen Apr 28 '17 at 01:40

1 Answers1

0

Try using AdminDirectory.Members.list, to list all the members of a group.

members = AdminDirectory.Members.list({
      groupKey: group.id
    });

Hope this helps.

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91