Get a list of Drives files that are shared

1,803 views
Skip to first unread message

Dave Parker

unread,
Mar 30, 2022, 3:58:26 PM3/30/22
to google-ap...@googlegroups.com
Hello,

Is it possible to use "gam user <user> show filelist" and limit the query only to those files which are shared?  Using the allfields option, I see that one of the fields for each file is "shared" and it is True/False, but Google's documentation does not indicate that you can use this field in a query to filter the results.  Is there any way to do this?

Thanks!

--
Dave Parker '11
Database & Systems Administrator
Utica University
Integrated Information Technology Services
(315) 792-3229
Registered Linux User #408177

Ross Scroggs

unread,
Mar 30, 2022, 4:03:40 PM3/30/22
to google-ap...@googlegroups.com
Dave,

With Advanced GAM you can say:
gam user <user> print filelist pm not role owner em fields id,name
pm not role owner em - only print files that have an ACL in addition to the owner ACL


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/CAHoJ95X0q9W%3DwEOXipOf3EHrpPxNoAsPbFjC8HfrWLqcSzPHyA%40mail.gmail.com.

Dave Parker

unread,
Mar 30, 2022, 4:25:47 PM3/30/22
to google-ap...@googlegroups.com
Hi Ross,

Thanks for the answer.  If I use a permissions match in Advanced GAM like that, does it fetch all of the results and then filter them in the application, or does it actually limit the results returned by the Drive API to only those which match?  I am trying to write a script which will go through all accounts in our domain which are suspended and pending deletion, and notify anyone who has a file shared with them from one of these accounts, so that they can copy anything they still need before the owner account is permanently deleted.  The script may process hundreds of accounts per run, and many of these accounts may have thousands of files but only a fraction of those are shared.  Being able to get a filtered result set from Google as opposed to a full listing may save quite a bit of time per run, if it's possible.

I hope this makes sense.

Thanks!

Ross Scroggs

unread,
Mar 30, 2022, 4:37:35 PM3/30/22
to google-ap...@googlegroups.com
Dave,

GAM gets all of the ACLs for each file and only includes the file (and all ACLS) in the output if there is a permission match.
It puts one ACL per file per row.

The API isn't much help in filtering in ths case, GAM does all of the work.

Send me a Meet/Zoom invitation to discuss,

Dave Parker

unread,
Mar 31, 2022, 9:16:28 AM3/31/22
to google-ap...@googlegroups.com
Hi Ross,

Thanks so much for clarifying.  It sounds like we'll be doing a full pull of the metadata and ACLs regardless, since the API does not provide a way to narrow the result set based on the shared status.  That was my assumption after looking at the docs, but it never hurts to ask the experts. :-)

On a related note, I tried to limit the results by using various other search terms, but most seem to fail.  For example, I tried limiting the search to files created after a specific date and got this:

$ gam user dparker show filelist query "createdTime >= '2022-02-01T00:00:01-05:00'"
Getting files for dpa...@utica.edu...

ERROR: 400: Invalid query - invalid
Got 0 Files for dpa...@utica.edu...
Owner,title,alternateLink

Based on the terms and operators listed in https://developers.google.com/drive/api/guides/ref-search-terms it seems like that should work.  Am I doing something wrong with my query?

Thanks! 

Reply all
Reply to author
Forward
0 new messages