Tuesday 18 May 2021

Get permissions of a Shared drive

The following Google Apps Script is designed to get permissions of a given Shared drive. It uses the Shared drive ID to then list a users email address and role they have. This page on Google Drive permissions is useful for what we need to put together to make the call.

 

Enable Drive API Service

Make sure you have followed the instructions here to enable the Drive API Service.

 

The Code

We need to include an optional argument that allows for us to work on Shared drives:

var optionalArgs = {
    supportsAllDrives: true
}

Next we can run the request to contact the Drive API and request a list of existing permissions:

var sharedDrivePermissions = Drive.Permissions.list(sharedDriveID, optionalArgs);

As you will see from the log a lot of information is returned so we need to narrow down the results. We also need to loop through each user and get their specific permissions:

var permissionItems = sharedDrivePermissions.items;

for (var i = 0; i < permissionItems.length; i++) {

    // get individual permission details
    var permission = permissionItems[i];
    var emailAddress = permission.emailAddress;
    var role = permission.role;

 

Download

Get permissions of a Shared drive download here (please use 'File' > 'Make a copy' for your own version).


No comments:

Post a Comment