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: "", // 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) {
// 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);

2 thoughts on “Google Workspace: Export list of all groups using Google App Script”
  1. Buenas tardes.
    He intentado utilizar el codigo pero me da este error:
    GoogleJsonResponseException: API call to directory.groups.list failed with error: Not Authorized to access this resource/api
    getGroups @ Có
    Me podríais ayudar.

    Un saludo

Leave a Reply

Your email address will not be published. Required fields are marked *