0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【GAS:Directory API+Groups Settings API】組織内の全Googleグループの設定をスプレッドシートに出力

Last updated at Posted at 2021-06-18

#概要

groups.listメソッドで一度に取得できる結果は200件までのため、200件を超える結果を取得するためdo-while文を使って記載している。
https://developers.google.com/admin-sdk/directory/reference/rest/v1/groups/list

Groups Settings APIで取得できるプロパティは以下の通り。
今回は例としてincludeInGlobalAddressListを使用。
https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups

A列にメールアドレス、B列に設定値を記載する仕様にしている。

#コード

function listAllGroups() {
//出力先シート名をgetSheetByName()内に指定
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('データ');
var allGroupdata = [];
var pageToken;
var page;

//シートの内容を全消去
sheet.clearContents();

//組織内に存在するすべてのGoogleグループを取得
do {
page = AdminDirectory.Groups.list({
//ドメインを指定
domain: 'test.co.jp',
maxResults: 100,
pageToken: pageToken
});
var groups = page.groups;

for (var i = 0; i < groups.length; i++) {
  var group = groups[i];
  var groupdata = [];
  groupdata.push(group.email);
  var groupSettings = AdminGroupsSettings.Groups.get(group.email);
  groupdata.push(groupSettings.includeInGlobalAddressList);

  allGroupdata.push(groupdata);
}

pageToken = page.nextPageToken;

} while (pageToken);

sheet.getRange(1, 1, allGroupdata.length, 2).setValues(allGroupdata);

}
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?