List Drive Permissions

If you ever wanted to get an overview of the sharing permissions of the files in your Google Drive, this little AppsScript can be helpfull.

 

 1function listFilePermissions() {
 2  // Get all files in your Drive
 3  var files = DriveApp.getFiles();
 4
 5  // Initialize an array to hold the output data
 6  var outputData = [];
 7  outputData.push(["File Name", "File ID", "Permission Type", "Permission", "Email/Domain", "Role"]); // Header row
 8
 9  // Loop through each file and get its sharing permissions
10  while (files.hasNext()) {
11    var file = files.next();
12    var fileName = file.getName();
13    var fileId = file.getId();
14    var permissions = file.getSharingAccess();
15    //Logger.log("Filename: " + fileName + " Sharing Access: " + permissions)
16    //var filePerms = file.getAccess(file.getId())
17    
18
19
20    // Loop through individual Permissions of each file
21    try {
22      const filePermissions = Drive.Permissions.list(fileId, {
23          fields: "*" // all fields
24      });
25
26      filePermissions.permissions.map(perm => {
27        outputData.push([fileName, fileId, `${perm.type}`, permissions, `${perm.emailAddress} - ${perm.domain}`, `${perm.role}`]);
28      });
29    } catch (e) {
30      Logger.log(e)
31      outputData.push([fileName, fileId, "", permissions, "", ""])
32    }
33  }
34  
35  // Create a new spreadsheet to write the data
36  var ss = SpreadsheetApp.create("Drive File Permissions List");
37  var sheet = ss.getActiveSheet();
38
39  // Write the output data to the spreadsheet
40  sheet.getRange(1, 1, outputData.length, outputData[0].length).setValues(outputData);
41
42  Logger.log("Spreadsheet URL: " + ss.getUrl())
43}

Save and then Run the script

The log will show any errors and end with the link to a new Sheet containing the information. Since one file can have many sharing permissions, one file can be repeated over several lines. Use the Table function in Sheet and group by File ID to get a better overview.