GAM is an open source command line tool for making changes to objects in the Google Admin console. It is thoroughly documented at the Github Wiki. The options available for use with GAM are displayed in specific sections on the right-hand side of the GAM Wiki. The scope of what is available to a GFE admin choosing to utilize GAM is vast. Setting up GAM is documented, but if you run into issues don’t hesitate to email firstname.lastname@example.org — this is a great use of Support Hours.
Some examples that may be relevant this time of the school year are covered below.
GAM single use cases
GAM comes into its own when it is combined with either output from itself or CSV files. This is covered in greater detail here.
However again a few example uses are provided below.
Let’s say you want to hide all groups from the Global Address List in Google Workspace. You would first print out a list of groups:
gam print groups > groups.csv
Then run a bulk command using that group.csv file as input:
gam csv groups.csv gam update group ~Email includeInGlobalAddressList false
To break that down, gam csv groups.csv lets GAM know we’re using the file groups.csv as an input. If you look at that file, it has one column with a header of Email and every row has a single group email address. gam update group ~Email includeInGlobalAddressList false is a full GAM command. Here’s where the bulk action comes in to play. Instead of specifying each individual group to update, we tell GAM to use the Email column in the input CSV as our list of groups. The ~ (tilde) tells GAM that is the name of a column header in the CSV. If you have a command that needs to reference multiple columns, you can use them this way.
Note: Column headers are case specific.
That works great, but outputting to a CSV file is an extra step. We can move a bit faster by taking the output of one GAM command and piping it to a bulk command. By piping input from GAM back into itself using a special pipe character, it is possible to perform changes on as many objects as required on a Google Workspace domain. Take this command for example:
gam print groups | gam csv – gam update group ~Email includeInGlobalAddressList true
Prints out a list of groups in CSV text format with a header called Email and it is then piped back into GAM using the ‘|’ character, instructing GAM that a csv is being used as input. It is then told to work on each row in the column ‘Email’ and change the setting to force the display of all groups in the Global Address List.
Bulk changes to Groups based on CSV input file
It is possible to obtain a list of groups
gam print groups allfields > c:\DestinationFolder\GroupsExport.csv
Then carry out modifications to the columns in this CSV using Excel/Sheets and then pipe that CSV back into GAM to action those changes. GAM will then alter each and every group as required.
gam csv alteredcsvfile.csv gam update group ~Email “SettingToBeAltered” ~”SettingColumnHeader”
gam csv alteredcsvfile.csv gam update group ~”Email” include_in_global_address_list ~”includeInGlobalAddressList” show_in_group_directory ~”showingroupdirectory”
This will hide all groups from the Global Address List (autocomplete in Drive/Gmail) and the Groups directory (being searchable via https://groups.google.com).
Moving all suspended users into a specific OrgUnit:
gam print users query “isSuspended=true orgUnitPath=/Student” | gam csv – gam update user “~primaryEmail” ou /Suspended/Students gal off
Would hunt for suspended users in the /Student OrgUnit and move them to an OrgUnit /Suspended/Students and hides them from the directory.