Google Workspace doesn’t have an option to export list of groups. This can be quite frustrating if you have lot of groups. Using Google Apps Script we can export all groups for a particular domain to a Google Sheet.

Created a Google Sheet and add below code to Google App Script. Ensure you add Admin API library and account has admin access.

function getGroups() {
var groups = [];
var options = {
domain: "mkerala.com", // Google Apps domain name
customer: "my_customer",
maxResults: 100,
projection: "basic", // Fetch basic details of users
viewType: "domain_public",
orderBy: "email" // Sort results by users
}
do {
var response = AdminDirectory.Groups.list(options);
response.groups.forEach(function(group) {
groups.push([group.email]);
});
// For domains with many users, the results are paged
if (response.nextPageToken) {
options.pageToken = response.nextPageToken;
}
} while (response.nextPageToken);
// Insert data in a spreadsheet
var thespreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = thespreadsheet.getActiveSheet();;
sheet.getRange(2,1,groups.length, groups[0].length).setValues(groups);
}

Leave a Reply

Your email address will not be published.