Search all of drive for a specific label

114 views
Skip to first unread message

Zach Miller

unread,
Jun 11, 2025, 12:31:43 PM6/11/25
to GAM for Google Workspace
Hey crew,

I am trying to search all of our drive files for a specific label. I have managed to search for a specific drive and user with the query below, but I am struggling a bit expanding this to search for all users Drives/MyDrives for this specific label. Does anyone have a way to accomplish this?

gam user myuser print filelist select teamdriveid <ID> query "'labels/LabelID' in labels" fields id,name,driveid,mimetype showlabels details

Ross Scroggs

unread,
Jun 11, 2025, 12:40:10 PM6/11/25
to google-ap...@googlegroups.com

gam config auto_batch_min 1 num_threads 10 redirect csv ./LabelledMyDriveFiles.csv multiprocess redirect stderr - multiprocess all users print filelist query "'labels/LabelID' in labels" fields id,name,mimetype showlabels details

# config auto_batch_min 1 num_threads 10 - Turn on parallel processing                                                                                                                                                                              

# redirect csv ./LabelledMyDriveFiles.csv multiprocess - Common output file                                                                                                                                                                          

# redirect stderr - multiprocess - Clean progress messages                                                                                                                                                                                           

# all users print filelist query "'labels/LabelID' in labels" fields id,name,driveid,mimetype showlabels details


Ross
----
Ross Scroggs



This email and any files transmitted with it are for the use of the intended recipient(s) only. If you have received this email in error, please notify the sender immediately and then delete it. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this email and any files transmitted with it without the sender's prior written permission. The information contained in this communication is confidential and proprietary information of Beyond Finance, LLC. and its Affiliates. 

--
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 visit https://groups.google.com/d/msgid/google-apps-manager/5b4039c6-3fe3-4cb2-9795-498b3c18e5b8n%40googlegroups.com.

Zach Miller

unread,
Jun 11, 2025, 3:03:51 PM6/11/25
to GAM for Google Workspace
Thanks Ross! 

Looks like this found some from the users but the rest have this output and I just want to make sure that this is expected when it fails to find files with that label?

User: username, Drive File/Folder Print Failed: Query ('me' in owners and ('labels/LabelID' in labels)) Invalid

Also, is there a way to do the same thing for all of our shared drives as well?

Ross Scroggs

unread,
Jun 11, 2025, 3:20:18 PM6/11/25
to google-ap...@googlegroups.com
Zach,

Send me  a private Meet/Zoom invitation and I'll help.

Ross
----
Ross Scroggs


Zach Miller

unread,
Jun 11, 2025, 3:22:19 PM6/11/25
to GAM for Google Workspace
Hey Ross, 

Unfortunately I am booked up until 3:30 CST. Can we sync then?

Ross Scroggs

unread,
Jun 11, 2025, 3:25:43 PM6/11/25
to google-ap...@googlegroups.com
Yes. Be sure and send the invitation to me, not the group.

Ross
----
Ross Scroggs


Zachary Zimbler

unread,
Jun 12, 2025, 12:01:05 AM6/12/25
to GAM for Google Workspace
This might be helpful (maybe not) — we've found when you traverse a large Drive corpus using the Google API you either hit rate limits or it goes really slow. The solve here is to use the Drive Inventory Report (currently 7 day lag, but getting better) which will dump your entire drive corpus to BigQuery. You can then query for files and such using SQL which will take a few seconds. I realize all that setup is painful, but so is sitting there watching your GAM command run for 2 hours.

Zach Miller

unread,
Jun 12, 2025, 9:58:28 AM6/12/25
to GAM for Google Workspace
Hey Zachary, 

Thanks for that information. I forgot to follow up here yesterday but myself and Ross had a call and managed to get this working! One of the caveats I have found is that the organizers have to have the ability to see the Label, or they won't populate any data when you run these queries.

For users and a specific label:
  • gam config auto_batch_min 1 num_threads 10 redirect csv ./LabelledMyDriveFiles.csv multiprocess redirect stderr - multiprocess all users print filelist query "'labels/<LabelID>' in labels" fields id,name,mimetype showlabels details

For All Shared Drives and a specific label. I'm fairly certain you could do this for specific shared drives if you wanted to with just populating the organizers file with those shared drives Organizers.

Get the Shared Drive organizers first: 
  • gam redirect csv ./shareddriveorganizers.csv print shareddriveorganizers
Then run a search for all organizers, since you have to have this to search the drives, with the drive labelID.
  • gam config num_threads 10 redirect csv ./LabeledSharedDriveFiles.csv multiprocess redirect stderr - multiprocess csv ./shareddriveorganizers.csv gam user "~organizers" print filelist select teamdriveid "~id" query "'labels/<LabelID>' in labels" fields id,name,mimetype,driveid showdrivename showlabels details

Reply all
Reply to author
Forward
0 new messages