Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Is there a GAM command to delete a file on a Team drive

627 views
Skip to first unread message

Jason Komendat

unread,
Jan 20, 2023, 1:46:35 PM1/20/23
to GAM for Google Workspace
WHat Im trying to do is schedule a file upload to a shared drive. That part worss with the below command. But as a task it doesn't overwrite the file it makes another copy each time the task is run. Is there any way to either force a copy to overwrite the file or delete the file first?

File add
gam user myemail add drivefile localfile C:\Path\file.csv teamdriveparentid 0AIjX3XUadsafawef

I found this but it doesn't work


gam user <User Email Address> delete drivefile teamdrive "<Shared Drive Name>" teamdrivefilename "<File Name>" purge

Rance Hall

unread,
Jan 20, 2023, 2:33:43 PM1/20/23
to google-ap...@googlegroups.com

What about searching for the ID of the file by name first, and then deleting the file by ID instead of name?

 

There are some circumstances where filenames get mangled just a little bit with unprintable characters so you never see the error.

 

Search for the file precisely, then start opening the search parameters till you are satisfied that you are getting the one and only file you want, then delete that one file by ID instead of name.

 

Not sure if that is your issue, but it’s worth a look.

 

R

 

-- 

Rance Hall

ESU10 Network Services

rance...@esu10.org

308-698-1919

 

 

 

From: 'Jason Komendat' via GAM for Google Workspace <google-ap...@googlegroups.com>
Date: Friday, January 20, 2023 at 12:46 PM
To: GAM for Google Workspace <google-ap...@googlegroups.com>
Subject: [GAM] Is there a GAM command to delete a file on a Team drive

[EXTERNAL EMAIL]

--
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/1c9ce314-01e7-44ad-a823-11c086f2b435n%40googlegroups.com.

Jason Komendat

unread,
Jan 20, 2023, 2:38:43 PM1/20/23
to GAM for Google Workspace
How do I search for the file inn GAM. Im uploading the file and it its called staff.csv but when I try this search command it says does not exist.

gam user myemail show filelist select teamdrive SHARENAME query "title='staff.csv'

Shared Drive Name: SHARENAME, Show Failed: Does not exist

Rance Hall

unread,
Jan 20, 2023, 3:59:01 PM1/20/23
to google-ap...@googlegroups.com

So there is a typo in your command in terms of a closing quote.  I’ll assume that’s an accident as you are saying you are getting a result.  Instead of an error.

 

Use a wildcard in your filename search and see if you get results.  Gradually work your way to a more generous search parameter.  I’m guessing that you will find it.

 

Rance

Maj Marshall Giguere

unread,
Jan 20, 2023, 4:40:53 PM1/20/23
to google-ap...@googlegroups.com
You didn't specify If you're using advance gam or regular gam.  The following will only be useful if you're using advanced gam.  Anyway I thought it couldn't hurt.

Be warned Google only cares about the fileID, you can have any number of files on a drive in the same folder all with the same name.  Worse you can have file names with UTF-16 characters mixed in to names.

First find the file ID:

If you are sure of the target file name:
$ gam user <UserIDWithAccess> show fileinfo teamdrive "shared drive name" teamdrivefilename "name of file" fields id
Look for the line "id:", this will give you file id.

If the file name is suspect the you can dump the entire contents of the shared drive to a csv file and pick through it with tools like grep/egrep

$ gam redirect csv ./Files.csv user <UserIDWithFullAccess> print filelist select teamdrive "shared drive name" fields id,name,mimetype

Be aware you may get more than one file with the target name.

I use this technique to upload a monthly spreadsheet (CSV) with our staff information.

Once you have the id you can update the original:
$ gam user <userIDWithPermissionToWriteToDrive> update drivefile id <IDofOriginalFile> retainname localfile ./staff.csv

Hope this is helpful,

V/r

Maj Marshall E Giguere

NH Wing Director of IT

Civil Air Patrol, U.S. Air Force Auxiliary

GoCivilAirPatrol.com

nhwg.cap.gov

Volunteers serving America's communities, saving lives, and shaping futures.



Maj Marshall E Giguere

NH Wing Director of IT

Civil Air Patrol, U.S. Air Force Auxiliary

GoCivilAirPatrol.com

nhwg.cap.gov

Volunteers serving America's communities, saving lives, and shaping futures.


Jason Komendat

unread,
Jan 24, 2023, 8:32:59 AM1/24/23
to GAM for Google Workspace
We're on GAM ADV Ver 6.18.04
Using your syntax of 
gam user <UserIDWithAccess> show fileinfo teamdrive "shared drive name" teamdrivefilename "name of file" fields id this command does see the file or 3 copies (the 2 in the shared drive trash) But I can't find a command to delete the file

gam user  <UserIDWithAccess> delete drivefile teamdrive  "shared drive name" teamdrivefilename "staff.csv" purge gives me "Purge Failes: Does not exist

Jason Komendat

unread,
Jan 24, 2023, 8:48:08 AM1/24/23
to GAM for Google Workspace
Rance I thought about that but ran into 2 issues. But the main one is with the 3 copies in there now they all have different IDs. so ti seems each time the task would add the file its a different ID so even if I query that ID it would be diufferent each time

On Friday, January 20, 2023 at 1:33:43 PM UTC-6 Rance Hall wrote:

Rance Hall

unread,
Jan 24, 2023, 9:40:33 AM1/24/23
to google-ap...@googlegroups.com

Jason:

 

Yes this is a problem of sorts, but I would fix it by deleting ALL copies of the file we are talking about and then work on discovering an existing single copy by id, then modifying it in the future so this multiple copy thing doesn’t happen again.

 

It will have a different document id for each user, so it’s not any extra work to discover it before updating the file.

 

Now shared/team drives might be a better answer as you can manage subscriptions to the share and just update the ONE file.

 

Hope this helps.

Jason Komendat

unread,
Jan 24, 2023, 2:08:35 PM1/24/23
to GAM for Google Workspace
I wa sable to find a command that worked

gam user kim delete drivefile teamdriveid idOfTheSharedDrive teamdrivefilename "Delete this file"

Reply all
Reply to author
Forward
0 new messages