Move all uncategorized + shared with with me + owned by Me

303 views
Skip to first unread message

Travis Fox

unread,
Apr 27, 2023, 3:52:08 PM4/27/23
to GAM for Google Workspace
Hello,

I am trying to figure out a way to move all files for a user that that fit the criteria of "is:unorganized owner:me and shared with me" into a folder in the users My Drive.

So far I can't even figure out how to print a filelist that captures what I find by just using the search in the users google drive with those parameters.

Closest I have gotten to getting a list is 'gam user Email collect orphans preview' but it also returns a bunch of files that don't show up in the google drive search.

Travis Fox

unread,
Apr 27, 2023, 4:19:51 PM4/27/23
to GAM for Google Workspace
I got a little bit closer, but still not quite there, by running: gam user em...@user.com print filelist fullquery "sharedWithMe=True and 'me' in owners" allfields todrive

From there I filtered the google sheet data showing all the rows with a blank parents.0.isRoot column. This returned me exactly the same file listing I'm looking for when I do a manual search of the users Google Drive.

I need to perform this on several hundred users though, so following this procedure to get the FileID's and move them isn't practical.

Ideally I could run a command to get the file Files ID's of jus these files and the owner users email into a CSV and then run another command with that CSV to move/copy those files into a folder on the users root of My Drive preserving any other sharing that was present on the file.

Ross Scroggs

unread,
Apr 27, 2023, 4:29:57 PM4/27/23
to google-ap...@googlegroups.com
Send me a Meet/Zoom invitation and I'll help


Ross

--
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/84f8f521-f795-4045-9491-61e732d7d872n%40googlegroups.com.


--

Admin Travis Fox

unread,
Apr 28, 2023, 6:11:43 PM4/28/23
to GAM for Google Workspace
We figured it out!

I was able to identify the specific files/folders that were truly orphaned by doing a search for is:unorganized owner:me in the users Google Drive web interface using the filter of the location Shared with me, and upon further inspection it was noted that all of these files have a parents.0.isRoot which is blank.

The first command we used created an "Orphaned Filesfolder at the root of all the users I needed to run this command on, listed in users.csv, and put the folder ID's into orphan_folderid.csv: 
gam redirect csv ./orphan_folderid.csv multiprocess csv users.csv gam user ~primaryemail create drivefile drivefilename "Orphaned Files" mimetype gfolder csv

The second command searches all of the users Google Drives for files/folders with the parent.0.isRoot as blank and puts a listing with the the relevant info such as email and File/Folder ID in a csv named orphans.csv:
gam config csv_output_row_filter "parents.0.isRoot:regex:^$" redirect csv ./orphans.csv multiprocess redirect stdout - multiprocess redirect stderr stdout csv orphan_folderid.csv gam user ~User print filelist fullquery "sharedWithMe=True and 'me' in owners" fields id,name,mimetype,owners.emailaddress,parents addcsvdata orphanparentid "~id" 

The final command goes through orphans.csv and moves all of the orphaned files to the Orphaned Files folder created at the users root in the first command:
gam redirect stdout ./fixorphans.txt multiprocess redirect stderr stdout csv orphans.csv gam user ~Owner update drivefile ~id parentid "~orphanparentid" 


Huge thank you to you Ross!
You're truly a gentleman, scholar and humanitarian sir.
Reply all
Reply to author
Forward
0 new messages