Categories
Code

File Permissions and Sharing Settings in Google Drive

This Google Script prints the sharing access and permissions of all files in your Google Drive. This helps you determine who has access to your Google Drive files. It uses the DriveApp service to retrieve all the files in your Google Drive and emails the report to the email address of the authorized Google user.

/* 


  ======================================
  Who Can See Your Files in Google Drive 
  ======================================
  
  Written by Amit Agarwal on 01/11/2014 
  
  Tutorial :: http://labnol.org/?p=28237
  

*/


function ScanGoogleDrive() {
    
  var files = DriveApp.getFiles();  
  var timezone = Session.getScriptTimeZone();
  var email = Session.getActiveUser().getEmail();
  
  var file, date, access, url, permission;
  var privacy, view, viewers, edit, editors;
  
  var rows = [["File Name", "Who has access?", "Date Created"]];
  
  while ( files.hasNext() ) {
    
    file = files.next();
    
    try {
      
      access     = file.getSharingAccess();
      permission = file.getSharingPermission();
      viewers    = file.getViewers();      
      editors    = file.getEditors();
      
      view = [];
      edit = [];
      
      date =  Utilities.formatDate(file.getDateCreated(), timezone, "yyyy-MM-dd HH:mm")
      url = '' + file.getName() + '';
      
      for (var v=0; v") + "";
  
  for (var i=1; i") + "";
  }
  
  html += "
For help, refer to this online tutorial written by Amit Agarwal."; MailApp.sendEmail(email, "Google Drive - File Permissions Report", "", {htmlBody: html}); }