1

I'm trying to get list of all users in my organization using Google Apps Script. This list should contain user full name, primary email and domain name in which user is located. I have several subdomains in my G Suite admin console.

Here is code that I'm trying to use. Can anybody tell me is that a good way to do so?

function test() {
var values = [];
var domains = AdminDirectory.Domains.list({
    customer: "my_customer"
}).domains;
domains.forEach(function(domain) {
    var options = ({
        customer: domain,
        orderBy: "email",
        maxResults: 100
    });

    do {
        var usersList = AdminDirectory.Users.list(options);
        usersList.forEach(function(user) {
            values.push([user.name.fullName, user.primaryEmail, user.customerId]);
        });

        if (usersList.nextPageToken) {
            options.pageToken = usersList.nextPageToken;
        }
    } while (usersList.nextPageToken);
})

}

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
BringIT
  • 91
  • 1
  • 6
  • https://stackoverflow.com/questions/49691457/get-users-by-department-from-admin-directory-api-using-google-apps-script – Cooper Feb 12 '21 at 17:00
  • Does the script work for you? Is there a particular part that it fails? Is there a part that you can do but maybe another part you don't understand? Which are they? – iansedano Feb 15 '21 at 09:50

0 Answers0