Return only the drive ID for a Shared Drive

1,166 views
Skip to first unread message

Jennifer LaPittus

unread,
May 11, 2021, 10:32:23 AM5/11/21
to GAM for Google Workspace
This may sound pretty basic but I'm new at GAM and trying to figure out syntax to simply return the drive ID for a Shared Drive when given the name of the Shared Drive.

Thank you,

Ian Bevan

unread,
May 11, 2021, 11:10:13 AM5/11/21
to GAM for Google Workspace
If you know the name of a user who is member of the drive you could try

gam user <User> show teamdrives query "name='<DriveName>'" asadmin

Jennifer LaPittus

unread,
May 11, 2021, 11:23:46 AM5/11/21
to google-ap...@googlegroups.com
Thank you, Ian. This returns all the info for the drive but want to be able to return only the shared drive ID (going to assign it to a variable in a script I'm writing). Any additional syntax that would do this?

Jennifer LaPittus
System Engineer


Disclaimer
Please help to protect the environment by not printing e-mails unnecessarily. The information contained in this communication from the sender is confidential. It is intended solely for use by the recipient and others authorized to receive it. If you are not the recipient, you are hereby notified that any disclosure, copying, distribution or taking action in relation of the contents of this information is strictly prohibited and may be unlawful.

--
You received this message because you are subscribed to a topic in the Google Groups "GAM for Google Workspace" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-apps-manager/PK21mRuk8y4/unsubscribe.
To unsubscribe from this group and all its topics, 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/df2397ff-e5b7-448b-97d7-7a02aae019e0n%40googlegroups.com.

Ross Scroggs

unread,
May 11, 2021, 11:33:54 AM5/11/21
to google-ap...@googlegroups.com
Jennifer,

With Advanced GAM you could do this:

$ gam info teamdrive teamdrive "TS Shared Drive 1" fields id

User: ad...@domain.com, Shared Drive: TS Shared Drive 1 (1235LiIe4dqxZUk9xyz)

  Shared Drive ID: 1235LiIe4dqxZUk9xyz

  Shared Drive Name: TS Shared Drive 1


or this:

$ gam info teamdrive teamdrive "TS Shared Drive 1" fields id formatjson

{"id": "1235LiIe4dqxZUk9xyz", "name": "TS Shared Drive 1"}


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/CAC7_LcotB8Qz0wsxcSSLL-m1_Smdq-jC0a9O4wEcRuppPLRaNg%40mail.gmail.com.


--

Maj Marshall Giguere

unread,
May 11, 2021, 2:47:32 PM5/11/21
to google-ap...@googlegroups.com
I don't know what shell or OS you're on, for *NIX with a bash shell here's what I use, it's buried in a function for ease of use.  GAM prints extraneous fields you don't ask for so a little filtering is necessary.

$> ID=$(gam print teamdrive matchname <drive name> fields id | tail +2 | gawk -F\, '{print $2;}');echo $ID
Getting all Shared Drives, may take some time on a large Google Workspace Account...
Got 42 Shared Drives...
HHGTG4242424242

if you're not using a bash shell I'm sure there's a PowerShell equivalent.

V/r
Maj Marshall E. Giguere, CAP
NH Wing Director of IT
U.S. Air Force Auxiliary
 

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/CAC7_LcotB8Qz0wsxcSSLL-m1_Smdq-jC0a9O4wEcRuppPLRaNg%40mail.gmail.com.

Jennifer LaPittus

unread,
May 11, 2021, 3:18:56 PM5/11/21
to google-ap...@googlegroups.com
Thank you so much to everyone!  I was able to get what I needed from all the info you sent over...

Jennifer LaPittus
System Engineer

Jennifer LaPittus

unread,
May 12, 2021, 12:25:55 PM5/12/21
to google-ap...@googlegroups.com
Just in case it helps anyone, here's some Powershell code I ended up using...

$user = Read-Host "What is the email address of the owner of the Shared Drive to be deleted?"
$folder = Read-Host "What is the name of the Shared Drive to be deleted?"
$mysplit = gam user $user print teamdrive matchname $folder fields id | %{ $_.Split(',')[1]; }
$id = $mysplit[1]
gam delete teamdrive $id
Write-Host "The Shared Drive",$folder,"with ID",$id,"was deleted successfully."

Jennifer LaPittus
System Engineer

Ross Scroggs

unread,
May 12, 2021, 3:55:52 PM5/12/21
to google-ap...@googlegroups.com
Jennifer,

Now that is clear that you're using Advanced GAM, you could do the following:
$user = Read-Host "What is the email address of the owner of the Shared Drive to be deleted?"
$folder = Read-Host "What is the name of the Shared Drive to be deleted?"
gam delete teamdrive teamdrive $folder
Write-Host "The Shared Drive ",$folder,"was deleted successfully."

<SharedDriveIDEntity> ::=

        <DriveFileItem> |

(teamdriveid <DriveFileItem>) | (teamdriveid:<DriveFileItem>)

<SharedDriveNameEntity> ::=

        (teamdrive <SharedDriveName>) | (teamdrive:<SharedDriveName>)

<SharedDriveEntity> ::=

        <SharedDriveIDEntity> |

        <SharedDriveNameEntity>


gam <UserTypeEntity> delete teamdrive <SharedDriveEntity>


You can delete by ID or name.

gam user us...@domain.com delete teamdrive <ID>


gam user us...@domain.com delete teamdrive teamdriveid <ID>

gam user us...@domain.com delete teamdrive teamdrive <Name>


Ross




--

Jennifer LaPittus

unread,
May 12, 2021, 4:25:42 PM5/12/21
to google-ap...@googlegroups.com
Thank you, Ross! That makes perfect sense. 

Jennifer LaPittus
System Engineer

Reply all
Reply to author
Forward
0 new messages