Contacts
Create
Basic Details
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
Add More Detailed info
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>"
Add to ContactGroup
gam user <User Email Address> create contact email <Contact Email Address> primary firstname "<First Name>" lastname "<Family Name>" contactgroup "<Contact Group Name>"
Via Google Sheet
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>"
Create ContactDelegate
User
The <Delegated User Email> can see the contacts from the <User Email Address>
gam user <User Email Address> create contactdelegate <Delegated User Email>
Create Contactgroup
Create Contact Group
gam user <user email address> create contactgroup name <new group name>
Delete Contact Group
gam user <user email address> delete contactgroup <group name>
Delete
Contacts in a Label
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>'
Contact Groups
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~~'"
Single Contact
gam delete contacts <Contact ID>
Delete ContactDelegate
User
The <Delegated User Email> will stop seeing the contacts from the <User Email Address>
gam user <User Email Address> delete contactdelegate <Delegated User Email>
Delete othercontacts
Contacts in 'Other Contacts' are identified with a resourceName similar to otherContacts/c888xxxxxxxxxx999. This resourceName is used to delete the contacts.
user
gam user <User Email Address> delete othercontacts <Resource Name>
Info
Contact ID
The <Contact ID> will look something like people/c1234567890
gam user <User Email Address> info contacts <Contact ID>
Managing Contacts
Add a Contact for a User
gam user <User Email Address> create contact name "<New Name>" email work <New.Email@Address.com> primary
Add a Contact for the users in an OU
gam ou </Path/To/OU> create contact name "<New Name>" email work <New.Email@Address.com> primary
Delete a Contact from the users in an OU
See above for the difference between delete and clear
gam ou </Path/To/OU> delete contacts emailmatchpattern <Contact.Email@Address.com>
Move OtherContacts
User
Move all a users OtherContacts to their My Contacts
gam user <User Email Address> move othercontacts emailmatchpattern ".*"
Print Contacts
Single User
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
For an OU
gam ou_and_children_ns </Path/To/OU> print contactgroups todrive
Number of contacts
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
Query
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>
Starting with
Query using the text a contact may start with.
gam user <User Email Address> print contacts emailmatchpattern <Starting With>.* todrive
Ending with
gam user <User Email Address> print contacts emailmatchpattern ".*<Ending With" todrive
Containing
gam user <User Email Address> print contacts emailmatchpattern ".*<Containg>.*" todrive
Print Othercontacts
User
gam user <User Email Address> print othercontacts todrive
Multiple Users
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 Contacts SelectContactGroup
Single Contact Group
Print the contacts in a single contact group
gam user <User Email Address> print contacts selectcontactgroup "<Group Name>" todrive
Replacedomain
Replace Domain
Replace all contacts containing the Old Domain with the New Domain
gam user <User Email Address> replacedomain contacts domain <Old Domain> <New Domain>
Update
Upadate All Contacts for A List of Users
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"
For a Single user
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"
For Multiple Users
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>
Update Contacts
For a single user
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
For users in an OU (and children OU)
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
Changing Contact Name
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
Update or remove Email
Check to see which contacts have the email address to be removed or updated
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
Update using gSheet (created above)
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
Clear from an OU (non suspended users) contacts
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 For All Users
Clear an email address from All non-suspended users
gam all users_ns clear contacts emailmatchpattern <email.address.to.clear>
Delete the Contact
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>
For an individual
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>
Update otherContacts
Move otherContacts
Move otherContaqcts to contacts and add to a contact group
gam user <User Email Address> update othercontacts emailmatchpattern ".*<@Old Domain>" contactgroup <Group Name>
View Contact Groups
View all the Contact Groups
gam user <user email address> show contactgroups
Print all the Contact Groups
The Google Sheet will also show the memberCount.
gam user <user email address> print contactgroups todrive
Print the Members of a Contact Group
gam user <user email address> print contacts selectcontactgroup "<Contact Group Name>" todrive
Print all the members of all the Contact Groups
gam user <user email address> print contactgroups | gam redirect stderr - multiprocess redirect csv ./UserContacts.csv multiprocess csv - gam user "~User" print contacts selectcontactgroup "~ContactGroupID"