Audit Google Drive for Files Larger than 50MB and Export to Sheet
Scans Google Drive storage, identifies massive videos, zip archives, and bloated presentations, and logs file name, owner, and size into a spreadsheet for storage cleanup.
https://www.googleapis.com/auth/drive.readonly • https://www.googleapis.com/auth/spreadsheetsfunction auditLargeDriveFiles() {
const minBytes = 50 * 1024 * 1024; // 50 MB
const files = DriveApp.searchFiles('trashed = false');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('StorageAudit');
const rows = [['File Name', 'Size (MB)', 'Owner', 'URL']];
while (files.hasNext()) {
const file = files.next();
const size = file.getSize();
if (size >= minBytes) {
const sizeMB = (size / (1024 * 1024)).toFixed(2);
const owner = file.getOwner() ? file.getOwner().getEmail() : 'Shared Drive';
rows.push([file.getName(), sizeMB, owner, file.getUrl()]);
}
}
sheet.clearContents();
sheet.getRange(1, 1, rows.length, 4).setValues(rows);
}Line-by-Line Code Explanation
Step-by-Step Setup & Deployment
- Create a sheet tab named "StorageAudit".
- Run the script to identify files consuming your pooled Google Workspace quota.
Best Practices for Quota & Rate Limit Management
When deploying this automation in Google Workspace, adhere to these operational principles:
- Batch Reads & Writes: Never execute
getValue()orsetValue()inside loops. Read ranges into memory in 1 call, process arrays in V8 memory, and commit changes with a singlesetValues()call. - Execution Timeouts: Apps Script terminates scripts exceeding 6 minutes. For multi-thousand row datasets, implement batch pagination with resume timestamps stored in
PropertiesService. - OAuth Permissions: Scope your manifest (
appsscript.json) narrowly to prevent security prompts from alarming external team members.
Frequently Asked Questions
Is Google Apps Script completely free to use?
Yes. Google Apps Script is built into all free Google accounts and Google Workspace editions. There are no server fees or subscription costs for running scripts within daily quotas.
Can I run this script on an automated schedule without keeping my computer on?
Yes. Time-driven triggers execute on Google's cloud infrastructure. Your script will run reliably even when your computer is closed or offline.
More Google Drive Automation Snippets
Auto-Organize Google Drive Uploads into Year / Month Subfolders
Scans an incoming upload folder in Google Drive, examines file creation dates, and moves files into organized subfolders formatted as YYYY/MM.
Google DriveAutomated Daily Spreadsheet Backup to Google Drive Archive
Creates a point-in-time timestamped backup copy of a critical production Google Sheet inside a dedicated backup folder every night.
Google DriveExport Google Sheets Range to JSON File in Google Drive
Transforms a spreadsheet table into a structured JSON array of objects (using column headers as keys) and saves the file directly to Google Drive for frontend or mobile consumption.