Update your Bookmarks to https://sites.google.com/view/gam--commands/home
List all the calendars to get the <Calendar Email/ID>.
gam ou_and_children_ns </Path/To/OU> print calendars todrive
From the GUI check the settings to get the <Calendar Email/ID>. Although this is not necessary.
gam calendar <Calendar Email/ID> show settings
Use this command to find the <Event ID> for the event to delete.
gam calendar <Calendar Email/ID> print events todrive
Test the command without the doit on the end.
gam calendar <Calendar Email/ID> delete event id <Event ID> doit
This will create a Google Sheet of the users with the <Old Email Address> in their contacts. The users will be under the header User.
gam ou_and_children_ns </Path/To/OU> print contacts emailmatchpattern <Old Email Address> todrive
To test, copy the headers and 1 row of data to another sheet. Run this command against this sheet.
gam csv gsheet <User Email Address> <File ID> '<Test Sheet Name>' gam user ~User update contacts emailmatchpattern <existing email address to change> email work <new email address> primary
If the test is sucsessful, change the name of the sheet to the one with all the data and rum the command again.
gam csv gsheet <User Email Address> <File ID> '<Sheet Name>' gam user ~User update contacts emailmatchpattern <existing email address to change> email work <new email address> primary
If you need to edit a document you are not an Editor of, you can use the following commands. N.B. only Editors can see file members. The fileinfo option will show you the file owner, which is then needed to add/remove your account.
If you know the exact name. The anyowner is needed as you are not the owner of the document. Save the FileID.
gam user <User Email Address> show filelist query "title = '<Exact File Name>'" anyowner
You need to know an existing Editor to enable you to be added as an Editor. This command will only work if you have view permission to the file.
gam user <Your Email Address> print fileinfo id <FileID>
If you do not have view permission, use this command.
gam show ownership <FileID>
gam user <Document Owner Email Address> add drivefileacl <FileID> user <Your Email Address> role editor
After making the edits you may want to remove yourself from the Document permissions.
gam user <Document Owner Email Address> delete drivefileacl <FileID> <Your Email Address>
To cut down internet usage during the day, we want to allow our Help Desk team to upload videos after peak hours (the teaching day) for other staff. They already have access to the local video files stored on our on-premis servers. These commands will allow us to proceed without the end user having to do anything.
Suggest using an underscore so this appears at the top of the Staff Users My Drive
gam user <Staff User Email Address> add drivefile drivefilename "<New Folder Name>" mimetype gfolder
gam user <Staff User Email Address> show filelist query "title = '<New Folder Name>'"
for example Folder ID= 1RDXXXXXXXXXXXXXXXXXXXXFST, taken from the webLink.
gam user <Staff User Email Address> add drivefileacl <Folder ID> user <Help Desk Email Address> role editor
gam user <Staff User Email Address> delete drivefileacl <Folder ID> <Help Desk Email Address>
Open up the Templates page and then the Dev Tools (Inspect).
Search for lh3.google.com/u/0/d/ for the template required and from the URL copy the File ID, for example 1VL67xxxxxxxxxxxxxxxxxxxxxxxxxxsCnEkUaXgRrg.
Then run;-
gam user <Your Email Address> print fileinfo id <File ID>
Or
gam show ownership <File Or Folder ID>
A series of commands to collect the permsions of a file and then use these to pupulate a file in the same folder.
gam user <User Email Address> print drivefileacls <File ID with Correct Permissions> oneitemperrow > ./<File Name>.csv
gam csv <File Name>.csv gam user <User Email Address> update drivefileacl <New File ID> ~permission.emailAddress role ~permission.role
gam redirect csv filelist.csv user <User Email Address> print filelist fields id,title
gam csv filelist.csv gam user <User Email Address> add drivefileacl ~id user <New User Email Address> role <role>
<role> could be reader, writer, commenter
This example will convert Jamboard files to PDFs and then upload them to the users MyDrive.
Get a list of Jam files for all users. Substitute for all users as desired
gam config auto_batch_min 1 redirect csv ./JamFiles.csv multiprocess redirect stdout - multiprocess redirect stderr stdout all users print filelist fields id,name,mimetype showmimetype gjam
Download the files into subdirectories by user
gam redirect stdout ./DownloadJamFiles.txt multiprocess redirect stderr stdout csv JamFiles.csv gam user "~Owner" get drivefile "~id" format pdf targetfolder "./JamFiles/#email#" overwrite false
As Admins can only move Folder from My Drive to Shared Drives (unless the setting is changed), the following can be used to move a users folder to their Shared Drive, with minimal effort from the user.
You will need;-
The user must share their folder with you
The exact name of the shared drive.
The Copy Folder Extension.
Using the Copy Folder Extension, create a copy of the shared folder.
gam user <Other Users Email> print teamdriveacls matchname '<Shared Drive Name>' fields id
If they have given you the wrong name or part of the name just run this command to see a list of all their Shared Drives. Then you should be able to work out the Shared Drive ID from the list.
gam user<Other Users Email> print teamdriveacls todrive
gam add drivefileacl <Shared Drive ID> user <Your Email Address> role organizer
Drag and drop the Copy of the Folder.
gam user <Your Email Address> delete drivefileacl <Shared Drive ID> <Your Email Address>
gam user <Your Email Address> delete drivefileacl <Drive Folder ID> <Your Email Address>
Filter the data to find the Shared Drive ID.
gam print teamdrives todrive
gam print drivefileacls <Team Drive ID> oneitemperrow todrive
gam add drivefileacl <Team Drive ID> user <new organizer email address> role organizer
gam user <Shared Drive Manager Email> delete drivefileacl <Shared Drive ID> <User Email To Delete>
This looks for files by title.
gam user <User Email Address> print filelist query "title='<File Title>'" id title > <CSV File Name>.csv
Or, saving the results to your My Drive. You will then need to manipulate the results into the CSV file before using to delete the files
gam user <User Email Address> print filelist query "title='<File Title>'" id title todrive
gam csv <CSV File Name>.csv gam user <User Email Address> delete drivefile ~id
gam user <User Email Address> print filelist corpora onlyteamdrives query "title='<File Title>'" id title > <CSV File Name>.csv
Create a sheet of the Team Drives a user belongs to
gam user <Leaving User Email Address> print teamdrives todrive
Or, to use a CSV for adding access permission
gam user <Leaving User Email Address> print teamdrives > <CSV File Name>.csv
Add Admin User to the Source Team Drive. I do this this way, rather than running the command as the leaving user, so that they do not get access to the new Shared Drive until it is all finished.
gam add drivefileacl <Team Drive ID> user <User Email Address> role organizer
Or, using the CSV from above
gam csv <CSV File Name>.csv gam add drivefileacl ~id user <User Email Address> role organizer
This gives an indication of how long the copy will take and can be used for checking after the copy. (NB filecounts only works with top level Team Drives)
gam user <User Email Address> print filecounts select teamdriveid <Shared Drive ID>
Or, if you just want the number
gam user <User Email Address> show filecounts select teamdriveid <Shared Drive ID>
gam user <User Email Address> copy drivefile <Source Shared Drive ID> recursive copytopfolderpermissions false copyfilepermissions false copysubfolderpermissions false teamdriveparentid <Destination Shared Drive ID> newfilename "<New Folder Name>"
Check the files in the copied folder, using;-
gam user <User Email Address> print filelist select <Copied Folder ID> countsonly fields mimetype
Or, Using VLOOKUP to compare the file list, to make sure all copied, of
gam user <User Email Address> print filelist select teamdriveid <Shared Drive ID> todrive tdtitle "<Sheet Name>"
AND
gam user <User Email Address> print filelist select teamdrivefilename "<Folder Name>" todrive tdtitle "<Sheet Name>"
Remove access for a single Shared Drive, where the <User Email Address> is your/Admin email address.
gam user <User Email Address> delete <Shared Drive ID> <User Email Address>
Or, remove using the CSV file created at the start of the process
gam csv <CSV File Name>.csv gam user <User Email Address> delete drivefileacl ~id <User Email Address>
gam show ownership <File Or Folder ID>
This user will later become the Owner
gam user <Owner Email Address> add drivefileacl id <File Or Folder ID> user <New User Email> role writer
gam user <New User Email> claim ownership id <File Or Folder ID> keepuser
gam user <New User Email> move drivefile <File Or Folder ID> teamdriveparentid <Team Drive ID>
These commands can be used to create multiple groups and set them as Web Forums (although this needs to be done via Group Settings GUI). I am sure with more time the names/emails could be combined into a single CSV and run more efficiently.
The <All Groups>.csv CSV contains a list of all the new email addresses for the groups and their names.
gam csv <All Groups>.csv gam create group ~email
Once the Groups have been created, you will need to access the Settings UI for each and select Web forum from Information > Advanced > Select a group type. This command then hides the group from the directory, so can only be found from the Groups homepage, makes sure the messages are archived and only allows Group Members to post.
gam csv <All Groups>.csv gam update group ~email name ~name includeinglobaladdresslist false isarchived yes whocanpostmessage all_members_can_post
gam csv <All Groups>.csv gam update group ~email add manager <Manager 1 Email Address>,<Manager 2 Email Address>
The <Group Memebers>.csv CSV has a list of all the email addresses for the members of the Group.
gam csv <Group Memebers>.csv gam update group <Group Email Address> add member user ~email
All viewing/posting will be via the Groups homepage.
gam csv <Group Memebers>.csv gam update group <Group Email Address> update member nomail ~email
This will create a gSheet for all the groups so the settings can be checked.
gam print groups domain <Domain> allfields todrive
But to see info for a single group
gam print groups select <Group Email Address> todrive
Find the users who have Directory sharing disabled. This is by OU, so you can run on top level OU (orgUnitPath='/') or any Sub-OU and only shows current (Not Suspended) users.
gam print users fields name,gal query "orgUnitPath='/<OU Name>' isSuspended=False" todrive tdtitle "Directory Sharing"
Use Google Sheets to remove the users who have includeInGlobalAddressList = TRUE. These users already have Directory sharing enabled. Save users as a CSV file (example gal.csv). Upload to Google Cloud.
Update users by running
gam csv gal.csv gam update user ~primaryEmail gal true
Or reset/update based on field from the CSV file.
gam csv gal.csv gam update user ~primaryEmail gal ~includeInGlobalAddressList
We have a set of accounts that are used for various scenarios, such as for exams, visiting groups of staff or students, interview candidates etc. We call these delegate accounts and are not related to the 'delegated email accounts' in Gmail.
This is the process I have used to reset these accounts after they have been used so that all the emails and Drive Docs are removed.
The delegates.csv contains the email addresses for all the accounts you need to clear.
This command assumes that there are less than 100 messages to delete. You may need to increase this if more messages are in the mailbox. You can replace max_to_delete 100 with before:yyyy/mm/dd but this will also delete the 3 emails from Google that appear when the account is created.
gam csv delegates.csv gam user ~email delete messages query deliveredto:~~email~~ max_to_delete 100
The easiest way is to use the following command. This will collect all the files and create a folder in the <My Email Address> account. The folder will be called "<delegate email address> old files". Inside this folder there will also be a folder called "<delegate email address> orphaned files" which will contain files shared with that account.
gam csv delegates.csv user ~email transfer drive <My Email Address>
These are the commands to first print out the members of a Group and then work out the combined daily aggregate data for each day in the range.
The _ns (not suspended) at the end of the group_ns will ensure that only active members will be listed.
gam print group-members group_ns <Group Email Address> todrive
Take the output Google Sheet and copy-paste transposed, the email list, so you have a row of email addresses. Save as a CSV and use this row of users to replace testuser1,testuser2,testuser3 in the command below.
gam report users select users testuser1,testuser2,testuser3 fields gmail:num_emails_received,gmail:num_emails_sent range <Start Date> <End Date> aggregatebydate todrive
This set of commands can be used to send out individual exam results to a set up students. The results are PDF files stored in a users My Drive.
The output of this command is the <FolderID> for the folder where the PDFs are stored.
gam user <Folder Owner Email> show filelist query "title ='<Folder Name>'" id title
gam user <Folder Owner Email> show filelist query "'<FolderID>' in parents" id title todrive
Next, add the student emails into the gSheet that has been created. Call the field 'email'.
Download as CSV and rename examresults.csv. Or Alternatively share using this gSheet direct.
This command will send the Drive File Share notification email to the students listed in the Google Sheet.
gam csv examresults.csv gam user <Folder Owner Email> add drivefileacl ~id user ~email role reader sendemail emailmessage '<Your Message>'
Alternatively, share the files using the gSheet created with all the student & PDF data.
gam csv gsheet <gSheet Owner Email> <gSheet File ID> '<gSheet Name>' gam user <Folder Owner Email> add drivefileacl ~id user ~email role reader sendemail emailmessage '<Your Message>'