Groups - Membership - [API documentation](#api-documentation) - [Python Regular Expressions](Python-Regular-Expressions) Match function - [Definitions](#definitions) - [Collections of Users](#collections-of-users) - [Select users based on suspension state](#select-users-based-on-suspension-state) - [Select users based on archived state](#select-users-based-on-archived-state) - [Add members to a group](#add-members-to-a-group) - [Delete members from a group](#delete-members-from-a-group) - [Synchronize members in a group](#synchronize-members-in-a-group) - [Delete members from a group by role or status](#delete-members-from-a-group-by-role-or-status) - [Update member roles and delivery options](#update-member-roles-and-delivery-options) - [Bulk membership changes](#bulk-membership-changes) - [Display user group member options](#display-user-group-member-options) - [Display group membership in CSV format](#display-group-membership-in-csv-format) - [Display group membership in hierarchical format](#display-group-membership-in-hierarchical-format) ## API documentation * https://developers.google.com/admin-sdk/directory/v1/reference/members ## Definitions See [Collections of Items](Collections-of-Items) ``` ::= allmail| abridged|daily| digest| disabled| none|nomail ::= (.)+ ::= "(,)*" ::= | | ::= @ ::= || ::= id: ::= || ::= "(,)*" ::= | | | See: https://github.com/taers232c/GAMADV-XTD3/wiki/Collections-of-Items ::= owner|manager|member ::= "(,)*" ::= customer|group|user ::= "(,)*" ::= See: https://developers.google.com/admin-sdk/directory/v1/guides/search-groups ::= "(,)*" ::= delivery|deliverysettings| email|useremail| group|groupemail| id| name| role| status| type ::= "(,)*" ``` ## Collections of Users Group membership commands involve specifying collections of users; for ``, see: [Collections of Users](Collections-of-Users) ### Select users based on suspension state When adding, deleting or synchronizing group members, to select only suspended or non-suspended users, use the following``: ``` (all users_ns|users_susp)| (domains_ns|domains_susp )| (group_ns|group_susp )| (groups_ns|groups_susp )| (group_users_ns|group_users_susp [members] [managers] [owners] [primarydomain] [domains ] [recursive|includederivedmembership] end)| (ou_ns|ou_susp )| (ou_and_children_ns|ou_and_children_susp )| (ous_ns|ous_susp )| (ous_and_children_ns|ous_and_children_susp ) ``` When adding, deleting or synchronizing group members, the `notsuspended|suspended` option can be used to select users in a particular suspension state. This option can be used with the following ``: ``` (all users)| (domains )| (group )| (groups )| (group_users [members] [managers] [owners] [primarydomain] [domains ] [recursive|includederivedmembership] end)| (ou )| (ou_and_children )| (ous )| (ous_and_children ) ``` ### Select users based on archived state When adding, deleting or synchronizing group members, the `notarchived|archived` option can be used to select users in a particular archived state. This option can be used with the following ``: ``` (all users|users_ns|users_susp|users_ns_susp)| (domains|domains_ns|domains_susp )| (group|group_ns|group_susp )| (groups|groups_ns|groups_susp )| (group_users|group_users_ns|group_users_susp [members] [managers] [owners] [primarydomain] [domains ] [recursive|includederivedmembership] end)| (ou|ou_ns|ou_susp )| (ou_and_children|ou_and_children_ns|ou_and_children_susp )| (ous|ous_ns|ous_susp )| (ous_and_children|ous_and_children_ns|ous_and_children_susp )| (query )| (queries ) ``` Prior to version `6.20.05`, the `notarchived|archived` option could only be used with the following ``: ``` (group|group_ns|group_susp )| (groups|groups_ns|groups_susp )| (group_users|group_users_ns|group_users_susp [members] [managers] [owners] [primarydomain] [domains ] [recursive|includederivedmembership] end) ``` ## Add members to a group ``` gam update group|groups create|add [] [usersonly|groupsonly] [notsuspended|suspended] [notarchived|archived] [[delivery] ] [preview] [actioncsv] | ``` When `` specifies a group or groups: * `usersonly` - Only the user members from the specified groups are added * `groupsonly` - Only the group members from the specified groups are added For `notsuspended|suspended`, see: [Select users based on suspension state](#select-users-based-on-suspension-state) For `notarchived|archived`, see: [Select users based on archived state](#select-users-based-on-archived-state) You can set the `delivery` option for the new members: * `allmail` - All messages, delivered as soon as they arrive * `abridged|daily` - No more than one message a day * `digest` - Up to 25 messages bundled into a single message * `none|nomail` - No messages * `disabled` - Remove subscription; this is what the documentation says, it's not clear what it means If `preview` is specified, the changes will be previewed but not executed. If `actioncsv` is specified, a CSV file with columns `group,email,role,action,message` is generated that shows the actions performed when updating the group. Gam adds the members in batches and pauses between batches in order to avoid exceeding Google's quota limits. The size of the batch is set in `gam.cfg/batch_size` and the pause in `gam.cfg/inter_watch_wait`. For add, values of 20 and 1 seem to give reasonable results. For each batch, if the quota rate limit is exceeded, Gam increases inter_batch_wait by .25 seconds. For example, ``` gam config batch_size 20 inter_batch_wait 1 update group testgroup@domain.com add members file users.lst ``` ### `actioncsv` Example Using `actioncsv` produces a CSV file showing the actions taken. ``` $ gam redirect csv AddUpdates.csv update group testgroup add members actioncsv users testuser2,testuser3 Group: testgroup@domain.com, Add 2 Members Group: testgroup@domain.com, Member: testuser2@domain.com, Added: Role: MEMBER (1/2) Group: testgroup@domain.com, Member: testuser3@domain.com, Add Failed: Member already exists. (2/2) $ more AddUpdates.csv group,email,role,action,message testgroup@domain.com,testuser2@domain.com,MEMBER,Added,Success testgroup@domain.com,testuser3@domain.com,MEMBER,Add Failed,Member already exists. ``` ## Delete members from a group ``` gam update group|groups delete|remove [] [usersonly|groupsonly] [notsuspended|suspended] [notarchived|archived] [preview] [actioncsv] | ``` `` is ignored, deletions take place regardless of role. When `` specifies a group or groups: * `usersonly` - Only the user members from the specified groups are deleted * `groupsonly` - Only the group members from the specified groups are deleted For `notsuspended|suspended`, see: [Select users based on suspension state](#select-users-based-on-suspension-state) For `notarchived|archived`, see: [Select users based on archived state](#select-users-based-on-archived-state) If `preview` is specified, the changes will be previewed but not executed. If `actioncsv` is specified, a CSV file with columns `group,email,role,action,message` is generated that shows the actions performed when updating the group. Gam deletes the members in batches and pauses between batches in order to avoid exceeding Google's quota limits. The size of the batch is set in `gam.cfg/batch_size` and the pause in `gam.cfg/inter_watch_wait`. For delete, values of 20 and 2 seem to give reasonable results. For each batch, if the quota rate limit is exceeded, Gam increases inter_batch_wait by .25 seconds. For example, ``` gam config batch_size 20 inter_batch_wait 2 update group testgroup@domain.com delete members file users.lst ``` ### `actioncsv` Example Using `actioncsv` produces a CSV file showing the actions taken. ``` $ gam redirect csv DeleteUpdates.csv update group testgroup delete members actioncsv users testuser2,testuser4 Group: testgroup@domain.com, Remove 2 Members Group: testgroup@domain.com, Member: testuser2@domain.com, Removed: Role: MEMBER (1/2) Group: testgroup@domain.com, Member: testuser4@domain.com, Remove Failed: Does not exist (2/2) $ more DeleteUpdates.csv group,email,role,action,message testgroup@domain.com,testuser2@domain.com,MEMBER,Removed,Success testgroup@domain.com,testuser4@domain.com,MEMBER,Remove Failed,Does not exist ``` ## Synchronize members in a group A synchronize operation gets the current membership for a group and does adds and deletes as necessary to make it match ``. This is done by specific role except for a special case where role is ignored. ``` gam update group|groups sync [|ignorerole] [usersonly|groupsonly] [addonly|removeonly] [notsuspended|suspended] [notarchived|archived] [remove_domain_nostatus_members] [[delivery] ] [preview] [actioncsv] (additionalmembers [] )* | ``` If `ignorerole` is specified, GAM removes members regardless of role and adds new members with role MEMBER. This is a special purpose option, use with caution and ensure that `` specifies the full desired membership list of all roles. If neither `` nor `ignorerole` is specified, `member` is assumed. When `` specifies a group or groups: * `usersonly` - Only the user members from the specified groups are added/deleted * `groupsonly` - Only the group members from the specified groups are added/deleted For `notsuspended|suspended`, see: [Select users based on suspension state](#select-users-based-on-suspension-state) For `notarchived|archived`, see: [Select users based on archived state](#select-users-based-on-archived-state) The `notsuspended|suspended` and `notarchived|archived` not only control what users are selected from `` but they also control what users are selected from ``. The `remove_domain_nostatus_members` option is used to remove members from the group that are in your domain but have no status. These members were added to the group before the user or group that they represent was created. Your domain is defined as the value from `domain` in `gam.cfg` if it is defined, or, if not, the domain of your Google Workspace Admin in oauth2.txt. You can set the `delivery` option for the new members: * `allmail` - All messages, delivered as soon as they arrive * `abridged|daily` - No more than one message a day * `digest` - Up to 25 messages bundled into a single message * `none|nomail` - No messages * `disabled` - Remove subscription; this is what the documentation says, it's not clear what it means Default: * members in `` that are not in the current membership will be added * members in the current membership that are not in `` will deleted When the `addonly` option is specified: * members in `` that are not in the current membership will be added * members in the current membership that are not in `` will not be deleted When the `removeonly` option is specified: * members in `` that are not in the current membership will not be added * members in the current membership that are not in `` will be deleted If `preview` is specified, the changes will be previewed but not executed. If `actioncsv` is specified, a CSV file with columns `group,email,role,action,message` is generated that shows the actions performed when updating the group. The option `additionalmembers [] ` can be used to specify members in addition to those specified with ``. For example, ``` gam update group teachers@domain.com sync member additionalmembers counselor@domain.com ou /Teachers ``` Gam adds/deletes the members in batches and pauses between batches in order to avoid exceeding Google's quota limits. The size of the batch is set in `gam.cfg/batch_size` and the pause in `gam.cfg/inter_watch_wait`. For sync, values of 20 and 1 seem to give reasonable results for the adds but the inter_batch_wait is probably too low for the deletes; for each batch, if the quota rate limit is exceeded, Gam increases inter_batch_wait by .25 seconds. For example, ``` gam config batch_size 20 inter_batch_wait 1 update group testgroup@domain.com sync members file users.lst ``` ### Examples using CSV file and Google sheets: * https://github.com/taers232c/GAMADV-XTD3/wiki/Collections-of-Users#examples-using-csv-files-and-google-sheets-to-update-the-membership-of-a-group ### Example Assume that at your school there is a group for each grade level and the members come from an OU; here is a sample CSV file GradeOU.csv ``` Grade,OU seniors@domain.org,/Students/ClassOf2023 juniors@domain.org,/Students/ClassOf2024 ... ``` This allows you to do: `gam csv GradeOU.csv gam update group ~Grade sync members ou ~OU` But suppose that at each grade level there are additional group members that are groups of faculty/staff; e.g., senioradvisors@domain.org. In this scenario, you can't do the `update group sync` command as the members that are groups will be deleted; the `usersonly` option allows the `update group sync` command to work: `gam csv GradeOU.csv gam update group ~Grade sync members usersonly ou ~OU` The users from the OU are matched against the user members of the group and adds/deletes are done as necessary to synchronize them; the group members of the group are unaffected. ### `actioncsv` Example Using `actioncsv` produces a CSV file showing the actions taken. ``` $ gam redirect csv SyncUpdates.csv update group testgroup sync members actioncsv users testuser1,testuser3,testuser4 Getting all Members for testgroup@domain.com, may take some time on a large Group... Got 3 Members for testgroup@domain.com... Group: testgroup@domain.com, Remove 1 Member Group: testgroup@domain.com, Member: testuser2@domain.com, Removed: Role: MEMBER Group: testgroup@domain.com, Add 1 Member Group: testgroup@domain.com, Member: testuser4@domain.com, Added: Role: MEMBER $ more SyncUpdates.csv group,email,role,action,message testgroup@domain.com,testuser2@domain.com,MEMBER,Removed,Success testgroup@domain.com,testuser4@domain.com,MEMBER,Added,Success ``` ## Delete members from a group by role or status ``` gam update group|groups clear [member] [manager] [owner] [usersonly|groupsonly] [notsuspended|suspended] [notarchived|archived] [emailclearpattern|emailretainpattern ] [remove_domain_nostatus_members] [preview] [actioncsv] ``` If none of `member`, `manager`, or `owner` are specified, `member` is assumed. By default, when clearing members from a group, all members, whether users or groups, are included. * `usersonly` - Clear only the user members * `groupsonly` - Clear only the group members By default, when clearing members from a group, all members, whether suspended/archived or not, are included. * `notsuspended` - Clear only non-suspended members * `suspended` - Clear only suspended members * `notarchived` - Clear only non-archived members * `archived` - Clear only archived users * `notsuspended notarchived` - Do not clear suspended and archived members * `suspended archived` - Clear suspended and archived members * `notsuspended archived` - Do not clear archived members * `suspended notarchived` - Do not clear suspended members Members that have met the above qualifications to be cleared can be further qualifed by their email address. * `emailclearpattern ` - Members with email addresses that match `` will be cleared; others will be retained * `emailretainpattern ` - Members with email addresses that match `` will be retained; others will be cleared The `remove_domain_nostatus_members` option is used to clear members from the group that are in your domain but have no status. These members were added to the group before the user or group that they represent was created. Your domain is defined as the value from `domain` in `gam.cfg` if it is defined, or, if not, the domain of your Google Workspace Admin in oauth2.txt. If `preview` is specified, the deletes will be previewed but not executed. If `actioncsv` is specified, a CSV file with columns `group,email,role,action,message` is generated that shows the actions performed when updating the group. Gam deletes the members in batches and pauses between batches in order to avoid exceeding Google's quota limits. The size of the batch is set in `gam.cfg/batch_size` and the pause in `gam.cfg/inter_watch_wait`. For delete, values of 20 and 2 seem to give reasonable results. For each batch, if the quota rate limit is exceeded, Gam increases inter_batch_wait by .25 seconds. For example, ``` gam config batch_size 20 inter_batch_wait 2 update group testgroup@domain.com clear members ``` ## Update member roles and delivery options ``` gam update group|groups update [] [usersonly|groupsonly] [notsuspended|suspended] [notarchived|archived] [[delivery] ] [createifnotfound] [preview] [actioncsv] | ``` There are two items that can be updated: role and delivery. If neither option is specified, the users are updated to members; this is the behavior from previous versions. Otherwise, only the specified items are updated. When `` specifies a group or groups: * `usersonly` - Only the user members from the specified groups are added * `groupsonly` - Only the group members from the specified groups are added By default, when updating members from organization units, all users, whether suspended or not, are included. * `notsuspended` - Do not include suspended users * `suspended` - Only include suspended users By default, when updating members from groups, all users, whether suspended/archived or not, are included. * `notsuspended` - Do not include suspended users * `suspended` - Only include suspended users * `notarchived` - Do not include archived users * `archived` - Only include archived users * `notsuspended notarchived` - Do not include suspended and archived users * `suspended archived` - Include only suspended or archived users * `notsuspended archived` - Only include archived users * `suspended notarchived` - Only include suspended users You can set the `delivery` option for the updated members: * `allmail` - All messages, delivered as soon as they arrive * `abridged|daily` - No more than one message a day * `digest` - Up to 25 messages bundled into a single message * `none|nomail` - No messages * `disabled` - Remove subscription; this is what the documentation says, it's not clear what it means If, when attempting to update the role of a group member, the group member is not found, the `createifnotfound` option causes Gam to add the member with the specified role. If `preview` is specified, the changes will be previewed but not executed. If `actioncsv` is specified, a CSV file with columns `group,email,role,action,message` is generated that shows the actions performed when updating the group. ## Bulk membership changes ### Example 1 The file Users.csv has a single column of email addresses, there is no header row. ``` user1@domain.com user2@domain.com ... gam update group group@domain.com sync members file Users.csv ``` The Google Sheet `user@domain.com ` has a single column of email addresses, there is no header row. Define an implicit header with the `fields Email` option. ``` user1@domain.com user2@domain.com ... gam update group group@domain.com sync members csvfile gsheet:Email user@domain.com fields Email ``` The Google Doc `user@domain.com ` has a single column of email addresses, there is no header row. ``` user1@domain.com user2@domain.com ... gam update group group@domain.com sync members file gdoc user@domain.com ``` ### Example 2 The CSV file Users.csv has one column of email addresses labelled Email. ``` Email user1@domain.com user2@domain.com ... gam update group group@domain.com sync members csvfile Users.csv:Email ``` The Google Sheet `user@domain.com ` has one column of email addresses labelled Email. ``` Email user1@domain.com user2@domain.com ... gam update group group@domain.com sync members csvfile gsheet:Email user@domain.com ``` ### Example 3 The CSV file Users.csv has two columns of email addresses labelled Email1 and Email2. ``` Email1,Email2 user1@domain.com,user2@domain.com user3@domain.com,user4@domain.com ... gam update group group@domain.com sync members csvfile Users.csv:Email1:Email2 ``` The Google Sheet `user@domain.com ` has two columns of email addresses labelled Email1 and Email2. ``` Email1,Email2 user1@domain.com,user2@domain.com user3@domain.com,user4@domain.com ... gam update group group@domain.com sync members csvfile gsheet:Email1:Email2 user@domain.com ``` ### Example 4 The file Groups.txt has a single column of group email addresses, there is no header row. You want to sync with the members of those groups. ``` group1@domain.com group2@domain.com ... gam update group group@domain.com sync members datafile groups Groups.txt ``` The Google Doc `user@domain.com ` has a single column of group email addresses, there is no header row. You want to sync with the members of those groups. ``` group1@domain.com group2@domain.com ... gam update group group@domain.com sync members datafile groups gdoc user@domain.com ``` ### Example 5 The CSV file Groups.csv has a single column of group email addresses labelled Group. You want to sync with the members of those groups. ``` Group group1@domain.com group2@domain.com ... gam update group group@domain.com sync members csvdatafile groups Groups.csv:Group ``` The Google Sheet `user@domain.com ` has a single column of group email addresses labelled Group. You want to sync with the members of those groups. ``` Group group1@domain.com group2@domain.com ... gam update group group@domain.com sync members csvdatafile groups gsheet:Group user@domain.com ``` ### Example 6 The CSV file GroupMembers.csv has headers: group,role,email Each row contains a group email address, member role (OWNER, MEMBER, MANAGER) and a member email address. The following command will synchronize the membership for all groups and roles. ``` gam redirect stdout ./MemberUpdates.txt redirect stderr stdout update group csvkmd GroupMembers.csv keyfield group subkeyfield role datafield email sync csvdata email ``` The Google Sheet `user@domain.com ` has headers: group,role,email Each row contains a group email address, member role (OWNER, MEMBER, MANAGER) and a member email address. The following command will synchronize the membership for all groups and roles. ``` gam redirect stdout ./MemberUpdates.txt redirect stderr stdout update group csvkmd gsheet user@domain.com keyfield group subkeyfield role datafield email sync csvdata email ``` You can also do `create|add`, `delete` and `update` in this manner. If you want to update a specific role, you can do one of the following. ``` gam redirect stdout ./MemberUpdates.txt redirect stderr stdout update group csvkmd ./GroupMembers.csv keyfield group matchfield role MEMBER datafield email sync member csvdata email gam redirect stdout ./ManagerUpdates.txt redirect stderr stdout update group csvkmd ./GroupMembers.csv keyfield group matchfield role MANAGER datafield email sync manager csvdata email gam redirect stdout ./OwnerUpdates.txt redirect stderr stdout update group csvkmd ./GroupMembers.csv keyfield group matchfield role OWNER datafield email sync owner csvdata email ``` ## Display user group member options Display user's group membership information. Delivery information is displayed; an additional API call per user is required. ``` gam info member|group-members gam info member|group-members | ``` ## Display group membership in CSV format By default, delivery information is not displayed. ``` gam print group-members [todrive *] [([domain|domains ] ([member|showownedby ]|[(query )|(queries )]))| (group|group_ns|group_susp )| (select )] [emailmatchpattern [not] ] [namematchpattern [not] ] [descriptionmatchpattern [not] ] [admincreatedmatch ] [roles ] [members] [managers] [owners] [membernames] [showdeliverysettings] * [fields ] [notsuspended|suspended] [notarchived|archived] [types ] [memberemaildisplaypattern|memberemailskippattern ] [userfields ] [(recursive [noduplicates])|includederivedmembership] [nogroupemail] [peoplelookup|(peoplelookupuser )] [unknownname ] [cachememberinfo [Boolean]] [formatjson [quotechar ]] ``` By default, the group membership of all groups in the account are displayed, these options allow selection of subsets of groups: * `domain|domains ` - Limit display to groups in the domains specified by `` * You can predefine this list with the `print_agu_domains` variable in `gam.cfg`. * `member ` - Limit display to groups that contain `` as a member; mutually exclusive with `query ` * `showownedby ` - Limit display to groups that contain `` as an owner; mutually exclusive with `query ` * `(query )|(queries )` - Limit groups to those that match a query; each query is run against each domain * `group ` - Limit display to the single group `` * `group_ns ` - Limit display to the single group ``, display non-suspended members * `group_susp ` - Limit display to the single group ``, display suspended members * `select ` - Limit display to the groups specified in `` * `showownedby ` - Limit display to groups owned by `` When using `query ` with the `name:{PREFIX}*` query, `PREFIX` must contain at least three characters. You can identify groups with the `All users in the organization` member with: * `query "memberKey="` - All versions * `member id:` - Version 6.10.06 or later These options further limit the list of groups selected above: * `emailmatchpattern ` - Limit display to groups whose email address matches `` * `emailmatchpattern not ` - Limit display to groups whose email address does not match `` * `namematchpattern ` - Limit display to groups whose name matches `` * `namematchpattern not ` - Limit display to groups whose name does not match `` * `descriptionmatchpattern ` - Limit display to groups whose description matches `` * `descriptionmatchpattern not ` - Limit display to groups whose description does not match `` * `admincreatedmatch True` - Limit display to groups created by administrators * `admincreatedmatch False` - Limit display to groups created by users By default, all members, managers and owners in the group are displayed; these options modify that behavior: * `roles ` - Display specified roles * `members` - Display members * `managers` - Display managers * `owners` - Display owners By default, all types of members (customer, group, user) in the group are displayed; when `recursive` is specified, the default is to only display type user members. This option modifies those behaviors: * `types ` - Display specified types By default, when displaying members from a group, all members, whether suspended/archived or not, are included. * `notsuspended` - Display only non-suspended members * `suspended` - Display only suspended members * `notarchived` - Do not include archived members * `archived` - Only include archived members, this is not common but allows creating groups that allow easy identification of archived users * `notsuspended notarchived` - Do not include suspended and archived members * `suspended archived` - Include only suspended or archived members * `notsuspended archived` - Only include archived members, this is not common but allows creating groups that allow easy identification of archived users * `suspended notarchived` - Only include suspended members, this is not common but allows creating groups that allow easy identification of suspended users Members that have met the above qualifications to be displayed can be further qualifed by their email address. * `memberemaildisplaypattern ` - Members with email addresses that match `` will be displayed; others will not be displayed * `memberemailskippattern ` - Members with email addresses that match `` will not be displayed; others will be displayed By default, the ID, role, email address, type and status of each member are displayed along with the group email address; these options specify which fields to display: * `membernames` - Display members full name; an additional API call per member is required * `showdeliverysettings` - Display delivery settings; an additional API call per member is required * `*` - Individual field names * `fields ` - A comma separated list of field names * `delivery|deliverysettings` - Specify this field to get delivery information; an additional API call per member is required * `userfields ` - For members that are users, display these user fields; an additional API call per member is required The additional API calls can be reduced with the `cachememberinfo` option; a single API call is made for each user/group and the data is cached to eliminate to need to repeat the API call; this consumes more memory but dramatically reduces the number of API calls. If member names are requested, names are not available for users not in the domain; you can request that GAM use the People API to retrieve names for these users. Names are not retrieved in all cases and success is dependent on what user is used to perform the retrievals. * `peoplelookup` - Use the administrator named in oauth2.txt to perform the retrievals * `peoplelookupuser ` - Use `` to perform the retrievals By default, when `membernames` is specified, GAM displays `Unknown` for members whose names can not be determined. Use `unknownname ` to specify an alternative value. By default, the group email address is always shown, you can suppress it with the `nogroupemail` option. By default, members that are groups are displayed as a single entry of type GROUP; this option recursively expands group members to display their user members. * `recursive` - Recursively expand group members The `recursive` option does not expand or display members of type CUSTOMER. The `recursive` option adds two columns, level and subgroup, to the output: * `level` - At what level of the expansion does the user appear; level 0 is the top level * `subgroup` - The group that contained the user Displaying membership of multiple groups or recursive expansion may result in multiple instances of the same user being displayed; these multiple instances can be reduced to one entry. * `noduplicates` - Reduce multiple instances of the same user to the first instance The `includederivedmembership` option is an alternative to `recursive`; it causes the API to expand type GROUP and type CUSTOMER members to display their constituent members while still displaying the original member. The API produces inconsistent results, use with caution. The options `recursive noduplicates` and `includederivedmembership types user noduplicates` return the same list of users. The `includederivedmembership` option makes less API calls but doesn't show level and subgroup information. Expanding a member of type CUSTOMER may produce a large volume of data as it will display all users in your domain. By default, Gam displays the information as columns of fields; the following option causes the output to be in JSON format, * `formatjson` - Display the fields in JSON format. By default, when writing CSV files, Gam uses a quote character of double quote `"`. The quote character is used to enclose columns that contain the quote character itself, the column delimiter (comma by default) and new-line characters. Any quote characters within the column are doubled. When using the `formatjson` option, double quotes are used extensively in the data resulting in hard to read/process output. The `quotechar ` option allows you to choose an alternate quote character, single quote for instance, that makes for readable/processable output. `quotechar` defaults to `gam.cfg/csv_output_quote_char`. When uploading CSV files to Google, double quote `"` should be used. ## Display group membership in hierarchical format ``` gam show group-members [([domain|domains ] ([member|showownedby ]|[(query )|(queries )]))| (group|group_ns|group_susp )| (select )] [emailmatchpattern [not] ] [namematchpattern [not] ] [descriptionmatchpattern [not] ] [admincreatedmatch ] [roles ] [members] [managers] [owners] [depth ] [notsuspended|suspended] [notarchived|archived] [types ] [memberemaildisplaypattern|memberemailskippattern ] [includederivedmembership] ``` By default, the group membership of all groups in the account are displayed, these options allow selection of subsets of groups: * `domain|domains ` - Limit display to groups in the domains specified by `` * You can predefine this list with the `print_agu_domains` variable in `gam.cfg`. * `member ` - Limit display to groups that contain `` as a member; mutually exclusive with `query ` * `showownedby ` - Limit display to groups that contain `` as an owner; mutually exclusive with `query ` * `(query )|(queries )` - Limit groups to those that match a query; each query is run against each domain * `group ` - Limit display to the single group `` * `group_ns ` - Limit display to the single group ``, display non-suspended members * `group_susp ` - Limit display to the single group ``, display suspended members * `select ` - Limit display to the groups specified in `` * `showownedby ` - Limit display to groups owned by `` When using `query ` with the `name:{PREFIX}*` query, `PREFIX` must contain at least three characters. You can identify groups with the `All users in the organization` member with: * `query "memberKey="` - All versions * `member id:` - Version 6.10.06 or later These options further limit the list of groups selected above: * `emailmatchpattern ` - Limit display to groups whose email address matches `` * `emailmatchpattern not ` - Limit display to groups whose email address does not match `` * `namematchpattern ` - Limit display to groups whose name matches `` * `namematchpattern not ` - Limit display to groups whose name does not match `` * `descriptionmatchpattern ` - Limit display to groups whose description matches `` * `descriptionmatchpattern not ` - Limit display to groups whose description does not match `` * `admincreatedmatch True` - Limit display to groups created by administrators * `admincreatedmatch False` - Limit display to groups created by users By default, all members, managers and owners in the group are displayed; these options modify that behavior: * `roles ` - Display specified roles * `members` - Display members * `managers` - Display managers * `owners` - Display owners By default, when displaying members from a group, all members, whether suspended/archived or not, are included. * `notsuspended` - Display only non-suspended members * `suspended` - Display only suspended members * `notarchived` - Do not include archived members * `archived` - Only include archived members, this is not common but allows creating groups that allow easy identification of archived users * `notsuspended notarchived` - Do not include suspended and archived members * `suspended archived` - Include only suspended or archived members * `notsuspended archived` - Only include archived members, this is not common but allows creating groups that allow easy identification of archived users * `suspended notarchived` - Only include suspended members, this is not common but allows creating groups that allow easy identification of suspended users By default, all types of members (customer, group, user) in the group are displayed; this option modifies that behavior: * `types ` - Display specified types Members that have met the above qualifications to be displayed can be further qualifed by their email address. * `memberemaildisplaypattern ` - Members with email addresses that match `` will be displayed; others will not be displayed * `memberemailskippattern ` - Members with email addresses that match `` will not be displayed; others will be displayed By default, members of type GROUP are recursively expanded to show their constituent members. (Members of type CUSTOMER are not expanded.) The `depth ` argument controls the depth to which nested groups are displayed. * `depth -1` - all groups in the selected group and below are displayed; this is the default. * `depth 0` - the groups within a selected group are displayed, no descendants are displayed. * `depth N` - the groups within the selected group and those groups N levels below the selected group are displayed. The `includederivedmembership` option causes the API to expand type GROUP and type CUSTOMER members to display their constituent members while still displaying the original member. The options `types user` and `includederivedmembership types user` return the same list of users. The `includederivedmembership` option makes less API calls but doesn't show hierarchy. Expanding a member of type CUSTOMER may produce a large volume of data as it will display all users in your domain. ### Display group structure To see a group's structure of nested groups use the `type group` option. ``` $ gam show group-members group testgroup5 types group Group: testgroup5@domain.com MEMBER, GROUP, testgroup1@domain.com, ACTIVE MEMBER, GROUP, testgroup2@domain.com, ACTIVE MEMBER, GROUP, testgroup3@domain.com, ACTIVE MEMBER, GROUP, testgroup2@domain.com, ACTIVE MEMBER, GROUP, testgroup4@domain.com, ACTIVE ``` To show the structure of all groups you can do the following; it will be time consuming for a large number of groups. ``` gam redirect stdout ./groups.txt show group-members types group ``` ### Examples #### Print a CSV of all members of a group regardless of role, all fields ``` gam print group-members ``` #### Print a CSV containing all managers emails ``` gam print group-members role manager fields email ``` #### Print a CSV output of all members and their emails only ``` gam print group-members role member fields email ``` #### Display group owners in your domain, but excluding groups where the email starts with a 4 digit code ``` gam print group-members domain emailmatchpattern not '^1234.*' roles owners ```