Update your Bookmarks to https://sites.google.com/view/gam--commands/home
Useful for creating Contact details for users outside your Domain.
gam user <User Email Address> create contact firstname <First Name> familyname <Family Name> email work <External Email Address> primary
gam user <User Email Address> create contact firstname <First Name> familyname <Family Name> website work <Website> primary phone work <Phone Number> primary email work <External Email Address> primary note "<Note for Contact>"
gam user <User Email Address> create contact email <Contact Email Address> primary firstname "<First Name>" lastname "<Family Name>" contactgroup "<Contact Group Name>"
Use the command to print the Contacts of a users ContactGroup (label) to a Google Sheet and then this command to transfer these contacts to a new user.
gam csv gsheet <Owner Email Address> <File ID> '<Sheet Name>' gam user <User Email Address> create contact firstname "~names.0.givenName" familyname "~names.0.familyName" email work "~emailAddresses.0.value" primary contactgroup "<Contact Group Name>"
The <Delegated User Email> can see the contacts from the <User Email Address>
gam user <User Email Address> create contactdelegate <Delegated User Email>
gam user <user email address> create contactgroup name <new group name>
gam user <user email address> delete contactgroup <group name>
Change delete to print to see the contacts that will be deleted. Add todrive to view the contacts in a Google Sheet.
gam user <User Email Address> delete contacts selectcontactgroup '<Label Name>'
By gSheet.
Use a print todrive command to create a gSheet of labels and edit this gSheet to contain the labels to delete. Change ~~formattedName~~ if necessary to match your column heading. Contacts in a label will not be deleted.
gam csv gsheet <User Email Address> <gSheet File ID> '<Tab Name>' gam user <Contact User Email> delete contactgroup "'~~formattedName~~'"
gam delete contacts <Contact ID>
The <Delegated User Email> will stop seeing the contacts from the <User Email Address>
gam user <User Email Address> delete contactdelegate <Delegated User Email>
Contacts in 'Other Contacts' are identified with a resourceName similar to otherContacts/c888xxxxxxxxxx999. This resourceName is used to delete the contacts.
gam user <User Email Address> delete othercontacts <Resource Name>
The <Contact ID> will look something like people/c1234567890
gam user <User Email Address> info contacts <Contact ID>
gam user <User Email Address> create contact name "<New Name>" email work <New.Email@Address.com> primary
gam ou </Path/To/OU> create contact name "<New Name>" email work <New.Email@Address.com> primary
See above for the difference between delete and clear
gam ou </Path/To/OU> delete contacts emailmatchpattern <Contact.Email@Address.com>
Move all a users OtherContacts to their My Contacts
gam user <User Email Address> move othercontacts emailmatchpattern ".*"
gam user <user email address> show contacts
But this may produce too many contacts to display on the screen. So this command will create a Google Sheet of the contacts
gam user <user email address> print contacts todrive
gam ou_and_children_ns </Path/To/OU> print contactgroups todrive
gam all users print contacts countsonly todrive
gam ou_and_children_ns </Path/To/OU> print contacts countsonly todrive
gam user <user email address> print contacts countsonly todrive
View users with a specific email address in their contacts.
gam ou_and_children_ns </Path/To/OU> print contacts query <Email to Search>
Change print to clear or delete to remove the email address or delete the contact.
gam ou_and_children_ns </Path/To/OU> [clear|delete] contacts query <Email to Search>
Query using the text a contact may start with.
gam user <User Email Address> print contacts emailmatchpattern <Starting With>.* todrive
gam user <User Email Address> print contacts emailmatchpattern ".*<Ending With" todrive
gam user <User Email Address> print contacts emailmatchpattern ".*<Containg>.*" todrive
gam user <User Email Address> print othercontacts todrive
Update a Google Sheet of the otherContacts for users listed in that Google Sheet. The <Sheet/Tab ID> will need to be a differnt sheet/tab than the one listing the users emails.
gam redirect csv - multiprocess todrive tdfileid <File ID> tdsheet id:<Sheet/Tab ID> tdupdatesheet tdretaintitle csv gsheet <Owner Email> <File ID> <Sheet Name> gam user ~email print othercontacts
Print the contacts in a single contact group
gam user <User Email Address> print contacts selectcontactgroup "<Group Name>" todrive
Replace all contacts containing the Old Domain with the New Domain
gam user <User Email Address> replacedomain contacts domain <Old Domain> <New Domain>
This sections deals with the need to update all the contacts (held in their contacts) of our Staff so that All Staff Family Names are in CAPITALS. The All Staff CSV can be created from running this command. Other commands can also be used. From the output you need a file with columns for email, familyname & name. the familyname field then needs to be converted to CAPITALS and the name field in the format Firstname FAMILYNAME. Save this as contact_names.csv.
gam ou_and_children_ns <Staff OU> print allfields todrive tdtitle "All Active STAFF Users"
To check the command, run the command as a single user. Add a single row to the CSV file.
gam csv contact_names.csv gam user <User Email Address> update contacts query ~email emailmatchpattern ~email familyname "~familyname" name "~name"
GAM does not really support nested loops so this needs to be run using the tbatch option, this allows commands to run as sub-threads. To create the batch file, copy the above command for all the users you want to run this command on, into a single file and save as contacts_batch.txt or similar.
The batch file will look something like this;-
gam csv contact_names.csv gam user <User1 Email> update contacts query ~email emailmatchpattern ~email familyname "~familyname" name "~name"
gam csv contact_names.csv gam user <User2 Email> update contacts query ~email emailmatchpattern ~email familyname "~familyname" name "~name"
gam csv contact_names.csv gam user <User3 Email> update contacts query ~email emailmatchpattern ~email familyname "~familyname" name "~name"
You can now run this command to process all the users.
gam tbatch <Batch File Name>
Assuming the email address is the primary email address.
gam user <user email address> update contacts emailmatchpattern <existing email address to change> email work <new email address> primary
Assuming the email address is the primary email address.
gam ou_and_children_ns <top level OU> update contacts emailmatchpattern <existing email address to change> email work <new email address> primary
For a single user. Assuming the email address is the primary email address.
gam user <user email address> update contacts <Contact ID> <Type of Name> <"New Name">
<Type of Name> ;- First Name = givenname | Family Name = familyname | Display Name = name
Check to see who (non suspended users in the STAFF OU and sub-OUs) has email@yourdomain.com in their contacts. This will produce a Google Sheet with the users.
gam ou_and_children_ns <Top Level OU> print contacts emailmatchpattern <email.address.to.check> todrive
From the gSheet created make a note of the <File ID> and change the sheet name to something easy, e.g. Contacts.
gam csv gsheet <Email Address of gSheet owner> <File ID> 'Contacts' gam user ~User update contacts emailmatchpattern <Old Email> email work <New Email> primary
The clear syntax will only remove the email address from the Contacts. If the contact details only contains the email address then the whole contact will be removed. However if the contact details includes other info, such as name, telephone etc, then this info will remain.
gam ou_and_children_ns <Top Level OU> clear contacts emailmatchpattern <email.address.to.clear>
As emailmatchpattern is a regex you can add more than 1 email address to clear or delete.
gam ou_and_children_ns <Top Level OU> clear contacts emailmatchpattern "<email>)|<email2>"
Clear an email address from All non-suspended users
gam all users_ns clear contacts emailmatchpattern <email.address.to.clear>
If you do not want to keep contacts with no email addresses after clearing, use the delete_cleared_contacts_with_no_emails option and they will be deleted.
Or force them to be deleted using
gam ou_and_children_ns <Top Level OU> delete contacts emailmatchpattern <email.address.to.delete>
CHECK
gam user <User Email Address> print contacts emailmatchpattern <email.address.to.CHECK>
CLEAR
gam user <User Email Address> clear contacts emailmatchpattern <email.address.to.CLEAR>
DELETE
gam user <User Email Address> delete contacts emailmatchpattern <email.address.to.DELETE>
Move otherContaqcts to contacts and add to a contact group
gam user <User Email Address> update othercontacts emailmatchpattern ".*<@Old Domain>" contactgroup <Group Name>
gam user <user email address> show contactgroups
The Google Sheet will also show the memberCount.
gam user <user email address> print contactgroups todrive
gam user <user email address> print contacts selectcontactgroup "<Contact Group Name>" todrive
gam user <user email address> print contactgroups | gam redirect stderr - multiprocess redirect csv ./UserContacts.csv multiprocess csv - gam user "~User" print contacts selectcontactgroup "~ContactGroupID"