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);
})
}