Remove All Shares on all drive files for suspended users

148 views
Skip to first unread message

Shaun Goodwin

unread,
May 2, 2024, 7:25:16 AMMay 2
to GAM for Google Workspace
I'm trying to achieve something similar to:

# Remove Recently Suspended Students from All Shared Drives https://sites.google.com/jis.edu.bn/gam-commands/services/shared-team-drive#h.nwhiphvdl2n5
gam redirect csv ./SuspendedStudentsOUSharedDriveAccess.csv ou "/Suspended Students" print shareddrives fields id,name
gam redirect stdout ./DeleteSuspendedStudentsOUSharedDriveAccess.txt multiprocess redirect stderr stdout csv ./SuspendedStudentsOUSharedDriveAccess.csv gam delete drivefileacl ~id ~User

For all drive files shared by suspended users
This was what I was trying to troubleshoot
# Remove Google Drive Shares from all recently Suspended Students
$users = gam ou "/Suspended Students" print users | ConvertFrom-Csv
foreach ($user in $users) {
    $userEmail = $user.User
    $files = gam user $userEmail show filelist | ConvertFrom-Csv
    foreach ($file in $files) {
        $drivefileid = $file.drivefileid
        $owneremail = $file."owners.email"
        $title = $file.title
        $permissions = $file.permissions
        if ($owneremail -ne "owners.email") {
            gam user $owneremail delete drivefileacl $drivefileid user "/Suspended Students"
        }
    }
}

Ross Scroggs

unread,
May 2, 2024, 10:54:23 AMMay 2
to google-ap...@googlegroups.com
Shaun,

Send me a Meet/Zoom invitation to discuss

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.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-manager/c572ecbb-9195-4545-8abb-a57d98e84cf2n%40googlegroups.com.

Christopher Kortmann

unread,
Jun 7, 2024, 12:44:28 PMJun 7
to GAM for Google Workspace
I'm looking to do the same thing. My organization has a lot of suspended students with publicly shared files. We'd like to remove all shared files from all suspended users. 

Is this something that was able to be easily scripted? 

NOTICE: This e-mail message may contain privileged or confidential information. The information contained in this e-mail message is only for the intended recipient. If the reader of this message is not the intended recipient, you are hereby notified that you have received this message and any attached documents in error, and that any review, dissemination, distribution, or copying of this message and any attached documents is strictly prohibited. If you have received this message in error, please notify us by telephone at (631) 382-2000 immediately, delete this e-mail and destroy any copies.

Ross Scroggs

unread,
Jun 7, 2024, 1:01:40 PMJun 7
to google-ap...@googlegroups.com
See:https://github.com/taers232c/GAM-Scripts3/blob/master/GetSharedFilePermissions.py

How are the suspended students identified? Are they in a specific OU?

Send me a Meet/Zoom inviration

Ross
----
Ross Scroggs


Christopher Kortmann

unread,
Jul 11, 2024, 12:34:13 PM (6 days ago) Jul 11
to GAM for Google Workspace
Thank you for pointing me in the right direction. I've been removing permissions by grade level, but I'm running into an issue when a user has a file shared with many users. 

Some of our students have files with 150 different shares. The resulting CSV is more than 1350 columns wide and the python script crashes. The error message I get is: 

Traceback (most recent call last):
  File "F:\GetSharedFilePermissions.py", line 49, in <module>
    for row in csv.DictReader(inputFile, quotechar=QUOTE_CHAR):
  File "C:\Program Files\Python312\Lib\csv.py", line 116, in __next__
    row = next(self.reader)
          ^^^^^^^^^^^^^^^^^
_csv.Error: field larger than field limit (131072)

Any suggestions? Thank you again!

Ross Scroggs

unread,
Jul 11, 2024, 1:08:50 PM (6 days ago) Jul 11
to google-ap...@googlegroups.com
Send me a Meet/zoom invitation and I'll help.

Ross
----
Ross Scroggs


Ross Scroggs

unread,
Jul 11, 2024, 1:24:29 PM (6 days ago) Jul 11
to google-ap...@googlegroups.com
Christopher,

Try this; it does the work of the script in a single command

gam config auto_batch_min 1 redirect csv ./filelistperms.csv multiprocess ou "/Path/to/OU" print filelist fields id,title,basicpermissions,mimetype pm not role owner em pmfilter oneitemperrow


Ross

----
Ross Scroggs


Christopher Kortmann

unread,
Jul 12, 2024, 1:34:58 PM (5 days ago) Jul 12
to GAM for Google Workspace
Ross:

I figured out what the issue was. There was a file being shared with a 499 character title. I was able to purge that file manually, and re-run the scripts successfully. 

Thank you for your help!

Best,
Chris

Reply all
Reply to author
Forward
0 new messages