Drive

Please Note

By default GAM will/may copy files from the Bin. To avoid this you can add excludetrashed on the end of the command.

Claim Ownership

The keepuser option retains the original owner with the role writer.

gam user <User Email Address> claim ownership id <Folder or File ID> keepuser

Copy Files & Folders

My Drive to Shared Drive

~OwnerEmail must be a member of the Shared Drive. Files copied will be recorded in the files-copied.csv and errors in the files-error.csv.

gam csv gsheet <Google Sheet Owner Email> <Google Sheet ID> '<Sheet (tab) Name>' gam redirect stdout ./files-copied.csv redirect stderr ./files-error.csv user ~OwnerEmail copy drivefile ~FolderID teamdriveparentid ~DestinationID mergewithparent no recursive depth -1

My Drive to My Drive

Files copied will be recorded in the files-copied.csv and errors in the files-error.csv.

gam csv gsheet <Google Sheet Owner Email> <Google Sheet ID> '<Sheet (tab) Name>' gam redirect stdout ./files-copied.csv redirect stderr ./files-error.csv user ~OwnerEmail copy drivefile ~FolderID parentid ~DestinationID mergewithparent no recursive depth -1

Shared Drive to My Drive

The email address must be the user who wants the copy and they must be a member of the Team Drive.

gam user <User Email Address> copy drivefile <Team Drive Folder ID> recursive copytopfolderpermissions false copyfilepermissions false copysubfolderpermissions false newfilename "<New Folder Name>"

Copy A File

gam user <User Email Address> copy drivefile <File to Copy ID> parentid <New Folder ID>

Folder Structure

Copy the folder structure without copying files. By default this will create a copy of the selected folder (and sub-folders) in the same location.

gam user <User Email Address> copy drivefile <Folder ID> recursive excludetrashed copysubfiles false copysubfolders true

Create

Files

The  main types of mimeType most needed are gdoc|gform|gpresentation|gsheet|gsite. But others are can be found here https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files-Manage#definitions 

gam user <User Email Address> create drivefile drivefilename "<File Name>" mimetype <mimeType> parentid <FolderID>

Folders

gam user <User Email Address> create drivefile drivefilename "<Folder Name>" mimetype gfolder parentid <FolderID>

Shortcuts - Files

By name

gam user <User Email Address> create drivefileshortcut name "<File Name>" parentname "<Folder Name>"

Use File and Folder IDs, which is more accurate

gam user <User Email Address> create drivefileshortcut id:<FileID> parentid <FolderID>

Shortcut - Folders

This will create a shortcut in the users MyDrive, with a specific name (<Name Of Shortcut>)

gam user <User Email Address> create drivefile drivefilename "<Name Of Shortcut>" mimetype gshortcut shortcut <FolderID>

Add a <Parent Folder ID> to specify a specific folder where the shortcut is created.

gam user <User Email Address> create drivefile drivefilename "<Name Of Shortcut>" mimetype gshortcut shortcut <FolderID> parentid <Parent Folder ID>

Driveactivity

Single User

gam user <User Email Address> print driveactivity todrive

Single User & Date Range

gam user <User Email Address> print driveactivity start <yyyy-mm-dd> end <yyyy-mm-dd> todrive

Single User, Date Range & Specific Folder

gam user <User Email Address> print driveactivity start <yyyy-mm-dd> end <yyyy-mm-dd> folderid <Folder ID> todrive

Drivefile (Delete)

Exact Name

gam user <User Email Address> delete drivefile query "name='<Exact File Name>'"

Drivefile (Move)

User

Move all the files from a users My Drive to a Shared Drive (folder). The <User Email Address> has to be a Manager of the destination Shared Drive.

gam user <User Email Address> move drivefile root teamdriveparentid <Shared Drive Parent ID> mergewithparent duplicatefolders merge createshortcutsfornonmovablefiles

Drivefile (Update )

Download, Print & Copy (File Only)

This option (Viewers and commenters can see the option to download, print, and copy) is found in the share settings > cog. To toggle this option, note that true = unticked &  false = ticked. By default the option is ticked (false) so to prevent use the true flag.

gam user <Manager Email> update drivefile <File ID> copyrequireswriterpermission true

Move Files to Single Folder

This may need checking as I think the some files are not moved if they are duplicates.

gam user <User Email Address> print filelist query "'<Current Parent Folder ID>' in parents and mimeType != 'application/vnd.google-apps.folder'" id title mimetype | gam csv - gam user "~Owner" update drivefile id "~id" parentid <Destination Folder ID>

By MIME type & createdTime

Example, move all Google Sheet files, created between 2 dates, from one folder to another folder. Change the +08:00 offset to suit your location

gam user <Owner Email Addreess> update drivefile query " '<Parent Folder ID>' in parents and  mimeType='application/vnd.google-apps.spreadsheet' and createdTime>='2022-08-01T00:00:00+08:00' and createdTime<'2023-07-31T00:00:00+08:00' " parentid <Destination Folder ID>

Starred

Change true|false as required.

gam user <User Email Address> update drivefile <File ID> starred <true|false>

Drivefileacl (Add)

Add Editor

To add an editor, you first need to find the owner email address, of the file.

gam user <File Owner Email> add drivefileacl <File ID> user <New Editor Email> role editor

Anyone in the Domain can View

gam user <File Owner Email> add drivefileacl <File ID> domain <Domain> withlink allowfilediscovery true role reader

Drivefileacl (Delete)

Permission ID

gam user <Owner Email Address> delete drivefileacl <File ID> "id:<Permission ID>"

Shared Email address

gam user <Owner Email Address> delete drivefileacl <File ID> "<Shared Email Address>"

Drivesettings

Check Drive Usage

Show presents the data in a readable format on the screen. Change to print to view in CSV format and add todrive option to create Google Sheet. The command can be performed on users, OUs or groups.

gam user <User Email Address> show drivesettings

gam ou </Path/To/OU> print drivesettings todrive

gam group <Group Email> print drivesettings todrive

Empty Drivetrash

User

Empty a users bin

gam user <User Email Address> empty drivetrash

Group

gam group <Group Email Address> empty drivetrash

OU

gam ou "</Path/To/OU>" empty drivetrash

Fileinfo

Specific File

gam user <user email address> show fileinfo <File ID>

Add permissions to the end to limit the info to just show the file permissions

gam user <user email address> show fileinfo <File ID> permissions

Root ID

gam user <user email address> show fileinfo root id

Exportlinks

Export the URL links for each document type shown in the File > Download options.

gam user <user email address> show fileinfo <File ID> exportlinks

Filepath

Specific File

Show the file path (location) of a file from its <File ID>

gam user <User Email Address> show filepath <File ID>

Report Drive

Doc_Id

gam report drive filter "doc_id==<File ID>" todrive

Doc_Title

gam report drive filter "doc_title==<Document Title>" todrive

Target_User

Shared With External Email

gam report drive filter "target_user==<External Email Addrerss>" todrive

Check the Drive activity for a User

Using gam report drive [todrive] [start <Time>] [end <Time>] [(user all|<UserItem>)] [event <String>] [filter|filters <String>] [ip <String>]

gam report drive todrive start <yyyy-mm-dd> end <yyyy-mm-dd> user <User Email Address>


Transfer

Transfer All Drive files & folders to another user account

A subfolder named olduser@domain.com old files will be created as a subfolder

gam user <source email> transfer drive <destination email> select <folder id> retainrole writer nonowner_targetrole source

Move a file from one folder to another within User account

gam user <User Email Address> move drivefile drivefilename <Drive File Name> parentname <Drive Folder Name>

Transfer all user info

A subfolder named olduser@domain.com old files will be created as a subfolder

gam user <source email> transfer drive <destination email>

Send an email to view file

gam user <user email address> add drivefileacl <file ID> user <Email Address of Recipient> role reader sendemail

Transfer a folder to a new user

Add withlink on the end when dealing with the domain or anyone ACL. The roll writer can be changed [owner|writer|commenter|reader] to suit.

gam user <Owner User Email> add drivefileacl 1fMKPq-dIiFxxxxxxxxxxxxx user <User Email Address> role writer

Transfer using CSV

The Target Folder needs to exist for this to work. See Add Folder.

gam csv <CSV File Name>.csv gam user "~OldOwner" transfer drive "~NewOwner" select "~FileId" targetfoldername "~TargetFolderName" targetuserfoldername "" retainrole writer

Transfer Files from Folder

Create a Google Sheet of the IDs of the files and folders to copy, from a specific folder. The showownedby me will only list the files the Original Owner owns. Then either transfer ownership or copy to a new folder

gam user <Original Owner Email> print filelist select ID <Folder-To-Copy-ID> showownedby me fields id todrive

Transfer the Ownership

gam csv gsheet <User Email Address> <gSheet DriveFileID> <gSheet Name> gam user ~Owner add drivefileacl ~id user <New Owner Email> role owner

Copy to New Folder

gam csv gsheet <User Email Address> <gSheet DriveFileID> <gSheet Name> gam user ~Owner copy drivefile ~id parentid <New Folder ID>

Transfer a Single File Type

Create a CSV file of all the files to transfer. Other mimetype can be found here https://developers.google.com/drive/api/v2/mime-types

gam redirect csv ./sheets.csv user <Existing Owner Email> print filelist query "mimeType='application/vnd.google-apps.spreadsheet'" fields id,name,mimetype

Transfer the files. No notifications will be sent. Existing owner will retain Edit permissions. The transfer.txt 

gam redirect stdout ./transfer.txt multiprocess redirect stderr stdout csv ./sheets.csv gam user ~Owner transfer ownership ~id <New Owner Email>

FileTree

Display the File Tree

This will list the file tree in the terminal.

gam user <User Email Address> show filetree

File for User

TXT Create a file of the file tree

gam redirect stdout ./FileTree.txt user <User Email Address> show filetree

gSheet

gam user <User Email Address> print filetree todrive

For Folder

This command will only show the files owned by the user. Remove excludetrashed if you want to show files in the bin, that have been deleted from the folder.

gam user <User Email Address> print filetree select id:<Folder ID> excludetrashed todrive tdtitle "<Google Sheet Title>"

Top Level Folders

Save the Filetree to Google Drive and only show the top level folders. Add the excludetrashed to prevent the folders in the Bin showing. However, this will analyse all the files in your MyDrive so may take a long time to complete. For just seeing the top level folders see the File List section

gam user <User Email Address> print filetree depth 0 showmimetype gfolder excludetrashed todrive

When reviewing the list, you will notice that My Drive will have a depth of -1 and the rows below this will be for each folder in the Drive. You may also see a line for Orphans with depth of -1 and the rows below this will be for the orphaned folders.

noindent

Use the noindent to reduce the spaces in the printed list.

gam user <User Email Address> print filetree showmimetype gfolder noindent

Print Diskusage

Root

The diskusage for a users My Drive.

gam user <User Email Address> Print diskusage root todrive

Folder

gam user <User Email Address> Print diskusage <Folder ID> todrive

Folder & Pathdelimiter

This allows you to specifiy the delimiter character used when displaying the folder path.

gam user <User Email Address> Print diskusage <Folder ID> pathdelimiter '<Text Character>' todrive

Print Drivefileacls

Single File

Print the permissions for a file. Useful when you want to remove a specific permission.

gam user <Owner Email Address> print drivefileacls <File ID> oneitemperrow todrive

Print Filecounts

All Users - filecounts & showsize 

gam config auto_batch_min 1 num_threads 10 redirect csv ./FileCounts.csv multiprocess redirect stdout - multiprocess redirect stderr stdout all users print filecounts summary plus showsize

Print FileList

For User

File list (ACL) for a specific user. Either use the CSV file or the corresponding Google Sheet.

gam redirect csv ./files.csv user <User Email Address> print filelist fields id,title,permissions,owners.emailaddress todrive

For User & not owned by Domain user

Files shared to a user by people outside their Domain.

gam config csv_output_row_filter "owners.0.emailAddress:notregex:@<Your Domain>" user <User Email Address> print filelist showownedby others fields id,name,owners.emailaddress,webviewlink todrive

Top Level Folders for User

This command will create a Google Sheet showing the top level folders you own. Other mimeTypes can be found on this page https://developers.google.com/drive/api/v3/mime-types.

gam user <User Email Address> print filelist query "'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" todrive

For a Specific Folder

All the files and folders in a folder owned by the user.

gam redirect csv - todrive tdtitle "<File Name>" user <User Email Address> print filelist select <Top Folder ID> fields id,name,webviewlink,owners.emailaddress,modifiedtime

Not-Owned Top Level Folders (Shared)

To view the folders at the top level, but shared with you use. You will need to use the showownedby others to display the results. If this is not used then any shred folders will be found in the search, you will see "Got 1(or more) Drive File/Folder that matched query ..." but nothing will be displayed. In other commands you can change the others to me or any as required.

gam user <User Email Address> print filelist fullquery "not 'me' in owners and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" showownedby others todrive

For displaying more information in the results use the fields option, for example.

gam user <User Email Address> print filelist fullquery "not 'me' in owners and 'root' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false" fields id,title,mimetype,owners.emailaddress showownedby others todrive

Google Sites

All Drives | Shared & My Drive

Create a Google Sheet with all the Google Sites from both users Drives and Team Drives. Looking into the API info, it appears that allTeamDrives can also be allDrives and this not affect the results. This command will show for all users.

gam all users show filelist corpora allTeamDrives anyowner showmimetype gsite fields name,id,title,alternateLink,createdDate,description,teamdriveid,teamdrivename todrive

My Drive only

gam all users print filelist query "mimeType = 'application/vnd.google-apps.site'" id name mimetype

Change all users as required, for example;-

gam user <User Email Address> show filelist ...

gam group <Group Email Address> show filelist ...

gam ou_and_children </Path/To/OU> show filelist ...

Some sites will be shared with multiple users. You can use the TRANSPOSE, UNIQUE & FILTER functions to show the which users have access to which sites. This example Google Sheet shows 2 ways to manipulate the data.

Name Contains, but not in Folder

Find a file(s) which have names containing specific text, but not located in a specified folder. Add corpora alldrives to include Shared Drives as well as user My Dive. This works for all files, except Google Sites.

gam user <User Email Address> print filelist query "name contains '<Part of File Name>' and not '<Folder ID>' in parents" filepath fields id,name,webviewlink todrive

For Google Sites, use this command. The csv_output_row_drop_filter option will exclude the rows where a column matches the value.

gam config csv_output_row_drop_filter "parents.0.id:regex:<Folder ID>" user <User Email Address> print filelist query "name contains '<Part of File Name>' not '<Folder ID>' in parents" filepath fields id,name,webviewlink,parents corpora alldrives todrive

OU

Create a Google Sheet showing a line per permission for users in an OU and child OUs

gam ou_and_children "</Path/To/Top/OU>" print filelist fields id,owners,basicpermissions pm role editor em pmfilter oneitemperrow todrive

Print Filelist (By)

By File Extension

Using file extension

gam user <User Email Address> print filelist fields title filenamematchpattern ".*<Part of File Extension>.*"

Using file name

gam user <User Email Address> print filelist fields title filenamematchpattern ".*<Part of File Name>*.*"

By File Name

Exact File Name

gam user <User Email Address> print filelist query "title = '<Exact File Name>'"

File Name starts with

gam user <User Email Address> print filelist filenamematchpattern "<Start of File Name>"

By File Content

These will search in Google Docs, Sheets, Forms, PDF, Microsoft Documents and PNG. I assume others as well.

Exact phrase, e.g. Hello & World next to each other.

gam user <User Email Address> print filelist query "fullText contains '\"Hello World\"'" todrive

Both Hello and World in the same document.

gam user <User Email Address> print filelist query "fullText contains 'Hello World'" todrive

By External Owner

Search for files that are shared with an domain user from an external email account.

gam user <User Email Address> print filelist id name owners fullquery "'<External Email Address>' in owners" anyowner

By Mime Type

For New Google Sites, stored in Google Drive.

For all users. Finding the mimeType = site (Google Sites). Check other mimeType here https://developers.google.com/drive/api/v2/mime-types

gam all users print filelist query "mimeType = 'application/vnd.google-apps.site'" todrive

To show specific fields

gam all users print filelist fields id,name,mimetype query "mimeType = 'application/vnd.google-apps.site'"

For a single user

gam user <User Email Address> print filelist query "mimeType = 'application/vnd.google-apps.site'" todrive

Or this command, but takes much longer. The mimeType can be changed, check other options here https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files

gam user <User Email Address> print filelist showmimetype gsite todrive

MIME Type contains

gam user <User Email Address> print filelist fields id,name,mimetype query "mimeType contains '<Text To Search>'" todrive

Using showmimetype

gam redirect csv ./Forms.csv ou </Path/To/OU> print filelist fields id,name,mimetype showmimetype gform fullpath todrive

By Mime Type & File Name

This is useful for finding the owners of Google Forms as the ID of the viewform view does not relate to the actual form. For my use-case, I have searched using the OU (our Staff OU) as generally these are the forms we need to find the owner of. The owners are both owners and editors of the forms.

gam ou_and_children <Top Level OU> print filelist query "fullText contains '\"<Form Title>\"'AND mimeType = 'application/vnd.google-apps.form'" fields id,name,webViewLink todrive

Adding corpora alldrives will search in Shared Drives as well as MyDrives. And using the filepath option will display the file path to make finding the location of the file easier. 

gam ou_and_children <Top Level OU> print filelist query "fullText contains '\"<Form Title>\"'AND mimeType = 'application/vnd.google-apps.form'" fields id,name,webViewLink filepath corpora alldrives todrive

Print Filelist Fullquery

From https://github.com/taers232c/GAMADV-XTD3/wiki/Users-Drive-Files-Display#file-selection-by-query 

Not Owned

gam user <User Email Address> print filelist fullquery "not '<Not Email Address>' in owners" id title

Print Filelist Query

User and Text Contains

gam user <User Email Address> print filelist query "fullText contains '\"<Text To Search>\"'" fields id,name,driveid filepath corpora alldrives todrive

User & SharedWithMe

Results show the sharedWithMeTime.

gam user <User Email Address> print filelist fullquery "sharedWithMe=True" showownedby others allfields todrive

User and CSV Files older than 90 days

Files that are older than 90 days from the viewedByMeTime.

gam user <User Email Address> print filelist querytime90d -90d query "mimeType = 'text/csv' and viewedByMeTime < '#querytime90d#'" fields id,name,createdtime,viewedbymetime,modifiedtime

All Users & Exact Name

gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "name='<Exact File Name>'" fields id,name,driveid filepath corpora alldrives todrive

All Users & Name Contains

gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "name contains '\"<Part of File Name>\"'" fields id,name,driveid filepath corpora alldrives todrive

All Users & Text Contains

This will search file content and titles

gam config auto_batch_min 1 multiprocessexit rc=0 redirect stdout - multiprocess redirect stderr stdout all users print filelist query "fulltext contains '\"<Text to Search>\"'" fields id,name,driveid filepath corpora alldrives todrive

All Users & Text Contains either/or

gam all users print filelist query "fullText contains '<Text Option 1>' or fullText contains '<Text Option 2>'" todrive

User & Minimumfilesize

gam user <User Email Address> print filelist minimumfilesize <File Size in Bytes> title size todrive tdtitle "<File Title>"

OU & Minimumfilesize

Remove countsonly if you want a list of all the files.

gam redirect csv ./BigFiles.csv ou "</Path/To/OU>" print filelist minimumfilesize <File Size in Bytes> title size countsonly todrive tdtitle "<File Title>"

User & Minimumfilesize & Application

NB. I need to confirm that the minimumfilesize is in Bytes

gam user <User Email Address> print filelist minimumfilesize <File Size in Bytes> query "mimeType='image/jpeg' or mimeType contains 'application'" todrive

User & Sub-folder Title

Using the ParentFolderID & Folder Name

gam user <User Email Address> print filelist query "'<ParentFolderID>' in parents and title='<Folder Name>'" id

Search in whole MyDrive

gam user <User Email Address> print filelist filepath query "title='<Folder Name>'" id todrive

User & Shared with FileLink

gam user <User Email Address> print filelist query "visibility='domainCanFind'or visibility='anyoneCanFind'" todrive

OU & Shared with Filelink

gam ou_and_children </Path/To/OU> print filelist fields id,name,permissions,webViewLink pm type domain domain <mydomain.com> role editor em query "(visibility='domainCanFind' or visibility='domainWithLink')" todrive

OU, Shared Drive & Shared with Filelink

gam ou_and_children </Path/To/OU> print filelist select teamdriveid <Shared Drive ID> fields id,name,permissions,webViewLink pm type domain domain <mydomain.com> role editor em query "(visibility='domainCanFind' or visibility='domainWithLink')" todrive

Shared with Group

(not fully tested)

gam config auto_batch_min 1 redirect csv ./SharedWithGroup.csv multiprocess all users print filelist fields id,name,mimetype,basicpermissions query "'<Group Email Address>' in readers or '<Group Email Address>' in writers" pm type group emailaddress '<Group Email Address>' em pmfilter oneitemperrow

Print Filerevisions

User

File revisions made by a specific user

gam user <User Email Address> print filerevisions <File ID> todrive oneitemperrow

List of Users

gam users <User1 Email Address>,<User2 Email Address>,<User3 Email Address>,<ETC>  print filerevisions <File ID> todrive oneitemperrow

Users in OU

Change ou to ou_and_children if members of sub-OUs are also to be counted.

gam ou </Path/To/OU> print filerevisions <File ID> todrive oneitemperrow

Purge (Files)

The purge option bypasses bin and deletes forever.

User | Single File

gam user <user email address> purge drivefile <file ID>

User | Specific File Type

gam user <user email address> print filelist query "mimeType='audio/mp3'" id title mimetype | gam csv - gam user ~Owner delete drivefile ~id purge

OU | Files Created before ...

gam ou "</Path/To/OU>" delete drivefile query:"createdTime<'<yyyy-mm-ddT00:00:00Z>'" purge

Update a Specific Sheet & Tab

This allows the Google Sheet to be shared so that other users always have the most up to date info.

Create the Sheet & Tab

Login as the user and create the Google Sheet and rename the tab. For this example the Sheet will be called UpdateByGAM and the Tab will be TabInfo.

Get Sheet and Tab ID

gam user <Sheet Owner Email> info sheet name "UpdateByGAM"

Look for Spreadsheet: 1234xxxxxxxxxxxxxxxxxxxxxxxxxxxXYZ & sheetId: 15xxxxxxxxx42 in the info listed.

Upload the Data

For example

gam redirect csv - todrive tduser <Sheet Owner Email> tdtitle UpdateByGAM tdtimestamp false tdfileid 1234xxxxxxxxxxxxxxxxxxxxxxxxxxxXYZ tdsheet id:15xxxxxxxxx42 tdupdatesheet tdnobrowser tdnoemail ous "'</Path/To/OU>'" print users fields primaryEmail,name,ou

NB the tdtimestamp false option will make sure the file name is not appended with the date/time of update. You may, however want to omit this if you want to know when the file was updated.

Via Local File

Use this command to update a Google Sheet using a local CSV file. For example if you generate a local CSV file, the contents can be used to update a Google Sheet.

gam user <Sheet Owner Email> update drivefile <File ID> csvsheet id:<Sheet ID> localfile <CSV File Name>.csv retainname

Modified Files

List of Files Modified between dates

gam user <User Email Address> print filelist query "modifiedTime >= '2020-01-01T00:00:00Z' and modifiedTime < '2020-02-01T00:00:00Z'" fields id,name,modifiedTime filepath todrive

Anyone with the Link Can Edit

View files with the permissions set to Anyone with the Link can edit

For a user

gam user <User Email Address> print filelist fields id,name,permissions,webViewLink pm type anyone withlink true role editor em todrive

For an OU

gam ou </Path/To/OU> print filelist fields id,name,permissions,webViewLink pm type anyone withlink true role editor em todrive

Show all fields

Change fields id,name,permissions,webViewLink to allfields

Delete Files with the permissions set to Anyone with the Link can edit

For a user

gam redirect csv ./AnyLinkEdit.csv user <User Email Address> print filelist fields id,name,permissions pm type anyone withlink true role editor em

Then to delete the ACLs

gam csv ./AnyLinkEdit.csv gam user <User Email Address> delete drivefileacl ~id anyonewithlink

AllowFileDiscovery

NB. Check syntax before running commands in a live enviroment.

Removing allowfilediscovery = true from users files. This command will create a Google Sheet with file permissions. Filter to only show files with allowfilediscovery = true AND either permissions.0.type = domain or the role, e.g. anyone. Change all users for user <User Email Address> or ou </Path/To/OU> as required.

gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess all users print filelist fields id,title,permissions,owners.emailaddress pm allowfilediscovery true em todrive

permissions.0.type = domain

gam csv gsheet <File Owner Email> <File ID> <Sheet Name> gam user ~Owner add drivefileacl ~id ~permissions.0.type ~permissions.0.domain role ~permissions.0.role allowfilediscovery false

permissions.0.type = anyone

gam csv gsheet <File Owner Email> <File ID> <Sheet Name> gam user ~Owner add drivefileacl ~id ~permissions.0.type role ~permissions.0.role allowfilediscovery false

Search | Files

Info on parameters for search: https://developers.google.com/drive/api/v3/search-files

Starred

Show all the files and folders starred, including in the trash. This will show the name and webViewLink for each file.

gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora alldrives todrive

Add excludetrashed to exclude the files in the trash.

gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora excludetrashed alldrives todrive

Add fields id,name,mimetype to display the file type (including folders) and the id.

gam user <user email address> print filelist fullquery "starred = true" showownedby any corpora excludetrashed fields id,name,mimetype alldrives todrive

Shared with anyone

gam config all users print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive

Or

gam all users print filelist filepath id title owners query "visibility='anyoneWithLink'" todrive

Shared with anyone, for active users in an OU (and sub OUs)

gam config ou_and_children_ns <top level OU> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive

Shared with anyone for a specific user

gam config user <user email address> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive

Or

gam user <user email address> print filelist filepath id title owners query "visibility='anyoneWithLink'" todrive

Shared with anyone for a specific OU (non-suspended users)

gam config ou_and_children_ns <top level OU> print filelist fields id,title,permissions permissionmatch type anyone endmatch todrive

Print a list of files (& folders), ID, title & permissions

gam user <user email address> print filelist id title permissions todrive

gam ou_and_children_ns <top level OU> print filelist id title permissions todrive

Print a list of files (& folders), ID, title & trashed

gam user <user email address> print filelist id title trashed todrive

Print a list of files (& folders) and Filepath

gam user <user email address> print filelist filepath todrive

Search for file types

Searching for all users or a single user. Output the file list to a CSV or todrive.

gam all users show filelist query "mimeType contains 'video/mp4'" allfields > filelist.csv

gam user <User Email Address> print filelist query "mimeType contains 'video/mp4'" allfields todrive

File Type Count for a Folder

Get a report of the file types in a folder and sub folders. Add anyowner if you want all the files.

gam user <User Email Address> print filelist select id:<FolderID> countsonly todrive

gam user <User Email Address> print filelist select name "<Top Folder Name>" countsonly todrive

Search for files owned by a Non-Domain user

gam user <User Email Address> print filelist id name owners fullquery "'<Non-Domain Email>' in owners" anyowner todrive

gam all users print filelist id name owners fullquery "'<Non-Domain Email>' in owners" anyowner todrive

Show files shared (or not) with a user

Find all files owned by others

gam user <User Email Address> print filelist id name owners showownedby others

Or

gam user <User Email Address> print filelist fullquery "not 'me' in owners" anyowner

Specify the user who is the owner

gam user <User Email Address> print filelist id name owners fullquery "'<Sharing User Email>' in owners" anyowner todrive

Add not in the query to search for files not shared by a user. 

gam user <User Email Address> print filelist id name owners fullquery "not'<Sharing User Email>' in owners" anyowner todrive

File Ownership

Using this command you can view the owner of a file that is "in use". It appears that it will only show files used within the last 180 days.

gam show ownership <File ID>

For older files you should be able to use this. Note the ' around the OU Path and " around the orgUnitPath.

gam print users query "orgUnitPath='/Path/To/OU'" | gam csv - gam user ~primaryEmail show drivefileacl <File ID> > results.txt

Search | Users

When you know the exact file title

This command will show the files owned by the user matching the <File Name>.

gam user <user email address> print filelist query "title = '<File Name>'" todrive tdtitle "<Results File Name>"

Searching of part of the file name

Using title contains '<Part of File Name>' you can search for files containing a character string.

gam user <user email address> print filelist query "title contains '<Part of File Name>'" todrive tdtitle "<Results File Name>"

The above commands will limit the results to those owned by the user. If you need to see all the files, those shared wi

gam user <user email address> print filelist query "title contains '<Part of File Name>'" anyowner todrive tdtitle "<Results File Name>

Users My Drive

Find the id of a users My Drive

gam user <user email address> show fileinfo root id title

id: <xxx My Drive ID xxx>

    name: My Drive

Use this ID to list the files in that users My Drive. The results will show File ID, Name and whether in Trash or not.

gam user <user email address> print filelist query "'<xxx My Drive ID xxx>' in parents" id name trashed title > rootfilesfolders.lst

Or, to save to your Google My Files

gam user <user email address> print filelist query "'<xxx My Drive ID xxx>' in parents" id name trashed todrive tdtitle "<File Name>"

By default, files in the Bin are listed;Trashed = True. To remove these run a fullquery with trashed=false.

gam user <user email address> print filelist fullquery "'<xxx My Drive ID xxx>' in parents and trashed=false" id name todrive tdtitle "<File Name>"

Include Files not Owned by user

The above commands will only list files owned by the user. So show all the files use anyowner.

gam user <user email address> print filelist fullquery "'<xxx My Drive ID xxx>' in parents and trashed=false" anyowner id name todrive tdtitle "<File Name>"

Delete (Files)

Delete a file from a user account

The file will be moved to the Bin

gam user <user email address> delete drivefile <file ID>

Remove "Anyone with the Link" Settings

gam user <user email address> delete drivefileacl <file ID> anyonewithlink

Delete all Videos

gam ou /Path/To/OU print filelist id mimetype name query "mimeType contains 'video/'" > VideoFiles.csv

Inspect and check VideoFiles.csv. If all OK to delete you can use this to delete files and bypass the bin.

gam csv VideoFiles.csv gam user ~Owner delete drivefile ~id purge

Folder Colours

Find the colour of the Top Folder and sub-folders

gam user <User Email Address> print filelist select drivefilename "<Top Folder Name>" showmimetype gfolder fields id,title,mimetype,foldercolorrgb showparent todrive

Change the colour of a folder

gam user <User Email Address> update fileinfo <Folder ID> folderColorRgb: <Colour Hex Value or Colour Name>

Change the Folder colour for sub-folders

Prior to running these commands, use the GUI to set a colour of the top folder and record the <Folder ID> from the Address bar.

Find the Parent Colour

gam user <User Email Address> show fileinfo <Folder ID> fields id,title,foldercolorrgb

This will show some details of the folder. Make note of the <colour code>, such as #16a765

Get the subfolders and output to a CSV file

gam redirect csv ./<CSV File Name>.csv user <User Email Address> print filelist select <Folder ID> fields id,title,foldercolorrgb showmimetype gfolder

Apply the colour to the subfolders

gam redirect stdout - multiprocess csv ./<CSV File Name>.csv gam user ~Owner update drivefile ~id foldercolorrgb "<colour code>"

Google Sheets

Download a specific sheet (tab) from  Google Sheet

gam user <User Email Address> get drivefile <File ID From The URL> csvsheet "<Sheet Name>"

Cells from a Google Sheet

Replace show with print if needed.

gam user <User Email Address> show sheetrange  <File ID From The URL> range '<Tab Name>!<Range>'

Different operating systems reqire different quoting syntax. A combination of " and/or ' may be needed.

Orphan files

User

If you create a file in Drive that you later can’t find, the file might have lost all of its parent folders. It becomes an orphaned file. The file still exists but is harder to find. 

gam user <User Email Address> collect orphans

OU

gam ou_and_children </Path/To/Top/OU> collect orphans

Preview

Create a Google Sheet of the Orphan files before transferring them.

gam user <User Email Address> collect orphans preview todrive

Folders

Add a new folder to a users Drive

gam user <User Email Address> add drivefile drivefilename "<Folder Name>" mimetype gfolder

gam all users add drivefile drivefilename "<Folder Name>" mimetype gfolder

Add a folder to a users Drive (top level - root). NB the user must have correct permissions for this to work.

gam user <User Email Address> update drivefile id <folder ID> addparent root

Share a folder with another user with the ownership retained.

The role can be changed to either reader or editor.

gam user <Owner Email Address> add drivefileacl <Folder ID> user <New Share Email Address> role editor

Ensure the user sees the folder in their My Drive

gam user <New Share Email Address> create drivefileshortcut <Folder ID>

Get a list of all the folders in a users My Drive

gam user <User Email Address> print filelist my_folders todrive

Get the FileID of a folder

gam user <User Email Address> show filelist query "title = '<Exact File Name>'"

FileID = 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9

Show file info to see who have permission

gam user <User Email Address> show fileinfo 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9

Or , for just info about the users

gam user <User Email Address> show drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9

List Folder IDs for a Parent Folder

gam user <User Email Address> print filelist todrive select 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 showmimetype gfolder fields id

Transfer a Folder

Add the 'new owner' to the folder

gam user <Original Owner Email> add drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 user <New Owner Email> role owner

Remove the original owner from the folder

gam user <New Owner Email> delete drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 <Original Owner Email>

OR: By viewing the fileinfo you can find the user id of the original owner.

gam user <New Owner Email> show drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9

This will show id: 1xxxxxxxxxxxxxxxxxxxxx6 for the user.

gam user <New Owner Email> delete drivefileacl 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 id:1xxxxxxxxxxxxxxxxxxxxx6

Convert a Local File

Convert a local file into a Google Sheet or Google Doc

gam user <User Email Address> update drivefile id 1Yvxxxxxxxxxxxxxxxxxxxxxxjif9 localfile <Local File Name>

get Drivefile (Download)

Formats

Files can be downloaded as in various formats. The most useful are (probably) CSV, DOC, JPG, PDF, TXT & ZIP.

As a PDF

This will work for both Drive files and Shared Drive files. If you are working in the Cloud then this will be saved in your designated 'Downloads' folder.

gam user <User Email Address> get drivefile <File ID> format pdf

Individual Sheet

Download an individual tab (sheet) from a Google Sheet.

gam user <User Email Address> get drivefile <File ID> gsheet id:<Sheet ID> format pdf

Download from the Cloud

The output from the above command will be something like this.

User: <User Email Address>, Drive File: <File Name>, Downloaded to: /home/user_name/Downloads/<File Name>.pdf, Type: Google Doc

To download to your local machine copy the file path /home/user_name/Downloads/<File Name>.pdf and use for downloading.

Get Drivefile Query

All Photos

Download all Photos from a Users Drive.

gam user <User Email Address> get drivefile query "mimeType = 'image/jpeg'" targetfolder /Path/To/Download/Folder

Untrash

User & Single File

The file will be restored to it's original location.

gam user <User Email Address> untrash drivefile <File ID>