GAM Command(s) Needed

1,629 views
Skip to first unread message

Bradley Stinson

unread,
Sep 25, 2018, 6:17:11 PM9/25/18
to google-ap...@googlegroups.com
Hey all,

I am looking for a command(s) to do the following on a list of docs in a csv. I have the urls of the docs so I can get the file id from there but I don't at this time know who the owners are. I am running regular gam. Any help is appreciated.

Update the sharing permissions to anyone in domain with the link can view.
Add a single user as a viewer.
Add a list of users with edit access.

Ross Scroggs

unread,
Sep 25, 2018, 6:41:35 PM9/25/18
to google-ap...@googlegroups.com
Here is my post from 8/3
I added a command to do this to my Advanced GAM (https://github.com/taers232c/GAMADV-XTD)

gam show ownership <DriveFileID>|(drivefilename <DriveFileName>) [formatjson]

gam print ownership <DriveFileID>|(drivefilename <DriveFileName>) [todrive [<ToDriveAttributes>]] [formatjson] [quotechar <Character>]


It is a cleaned up version of the following:

gam report drive filter="doc_id==Put File ID here" > id.csv

Open id.csv in a spreadsheet program

Look in the columns parameters.N.name for a row with the value owner; the adjacent column parameters.N.value will have the owner email address.


This only works if the file has been accessed in the last 180 days.


Start with a CSV file fileids.csv with one column:

id

dddjks-dghhjh-dhjshdjh

uuidsidosiso-hdjsjdjs


gam redirect csv ./fileowners.csv multiprocess csv fileids.csv gam print ownership ~id


fileowners.csv has these headers: Owner,id,title,type,ownerIsTeamDrive,teamDriveId


Update the sharing permissions to anyone in domain with the link can view.
gam csv fileowners.csv gam user ~Owner add drivefileacl ~id anyone role reader withlink
Add a single user as a viewer.
gam csv fileowners.csv gam user ~Owner add drivefileacl ~id user f...@domain.com role reader
Add a list of users with edit access.
Even advanced gam doesn't handle a list of users, you have to do each user individually or put them in a group
gam csv fileowners.csv gam user ~Owner add drivefileacl ~id user f...@domain.com role editor
gam csv fileowners.csv gam user ~Owner add drivefileacl ~id user g...@domain.com role editor

gam csv fileowners.csv gam user ~Owner add drivefileacl ~id group foo...@domain.com role editor

Ross


--
You received this message because you are subscribed to the Google Groups "GAM for G Suite" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
To post to this group, send email to google-ap...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-apps-manager.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAC6ikXHOUxb9OLAEj3Hh2RhkwLt6bhzYZogQcaA5%3D-gVtbdurw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--

Bradley Stinson

unread,
Sep 25, 2018, 6:55:45 PM9/25/18
to google-ap...@googlegroups.com
Running this as a bulk command how do use ~fileids inside of the double quotes in gam report drive filter="doc_id==Put File ID here" > id.csv

Bradley Stinson

unread,
Sep 25, 2018, 6:56:54 PM9/25/18
to google-ap...@googlegroups.com
Nevermind i'll do it in the csv itself

Bradley Stinson

unread,
Sep 25, 2018, 7:34:26 PM9/25/18
to google-ap...@googlegroups.com
When running the command below I am getting the error below that

gam csv fileids.csv gam report drive ~command > id.csv

ERROR: filter="doc_id==MyDocIdHere" is not a valid argument to "gam report"

the ~command is the whole string
filter="doc_id==MyDocIdHere"


I also tried running the below and changing the ~command to what is below it. This was just putting a space in between the filter and query and ditching the = sign.

gam csv fileids.csv gam report drive filter ~command2 > id.csv

with ~command 2 as "doc_id==MyDocIdHere"
IERROR: 400: Invalid request: Parameter "doc_id not found in manifest. - invalid
it just throws an error and doesn't even write it to the csv because the command breaks before that.

What do I have wrong?

Ross Scroggs

unread,
Sep 25, 2018, 9:04:01 PM9/25/18
to google-ap...@googlegroups.com
Bradley,

Spurious = after filter in original post.
Use ~~id~~ to embed a column value inside an argument.
Add event create to cut down on output

gam csv fileids.csv gam report drive filter "doc_id==~~id~~" event create > id.csv


With standard Gam id.csv will be ugly as multiple processes are writing to the file at the same time, the data will be intermingled; there will a header row per file id.

You can clean it up a bit by executing this command first: export GAM_THREADS=1

You'll still have multiple header rows but the data from different ids will not get intermingled.


Ross



For more options, visit https://groups.google.com/d/optout.


--

Bradley Stinson

unread,
Sep 26, 2018, 12:45:44 AM9/26/18
to google-ap...@googlegroups.com
This worked thanks a lot for your help.

Prashant Bhargava

unread,
Feb 21, 2024, 11:07:33 AM2/21/24
to GAM for Google Workspace
Hi, 

When I try to run gam redirect csv ./fileowners.csv multiprocess fileids.csv gam print ownership ~id 

I get back: 
ERROR: Invalid choice (fileids.csv): Expected <all|cigroup|cigroup_users|cigroups|courseparticipants|cros|cros_ou|cros_ou_and_children|cros_ou_and_children_queries|cros_ou_and_children_query|cros_ou_queries|cros_ou_query|cros_ous|cros_ous_and_children|cros_ous_and_children_queries|cros_ous_and_children_query|cros_ous_queries|cros_ous_query|cros_sn|croscsv|croscsv_sn|croscsvdata|croscsvfile|croscsvfile_sn|crosfile|crosfile_sn|crosqueries|crosquery|csv|csvdata|csvdatafile|csvfile|csvkmd|csvsubkey|datafile|domains|domains_ns|domains_susp|file|group|group_inde|group_ns|group_susp|group_users|group_users_ns|group_users_select|group_users_susp|groups|groups_inde|groups_ns|groups_susp|licenses|oauthuser|ou|ou_and_children|ou_and_children_ns|ou_and_children_susp|ou_ns|ou_susp|ous|ous_and_children|ous_and_children_ns|ous_and_children_susp|ous_ns|ous_susp|queries|query|students|teachers|user|users>
Help: Syntax in file /Users/pbhargava/bin/gamadv-xtd3/GamCommands.txt
Help: Documentation is at https://github.com/taers232c/GAMADV-XTD3/wiki 

Am I not specifying the path to the .csv? Thanks! 

Ross Scroggs

unread,
Feb 21, 2024, 11:10:49 AM2/21/24
to google-ap...@googlegroups.com
You're missing the csv keyword in front of fileids.csv
 gam redirect csv ./fileowners.csv multiprocess csv fileids.csv gam print ownership ~id 

Ross
----
Ross Scroggs



You received this message because you are subscribed to the Google Groups "GAM for Google Workspace" group.

To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-man...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages