Build a Drive quota early-warning system
Alert Northwind before storage runs out — email when usage crosses 80%.
Published Oct 20, 2025
A full Drive is a quiet emergency. Uploads start failing, shared documents stop syncing, and the first anyone hears of it is a colleague asking why their file will not save. By then it is a scramble. Northwind would much rather get a gentle heads-up while there is still room to clear space or buy more.
This script checks the account’s storage quota and emails a warning the moment usage crosses 80%. It runs on a daily timer, costs nothing when there is plenty of room, and turns a sudden outage into a calm, planned cleanup.
What you’ll need
- The advanced Drive API service enabled in the Apps Script project
(Services → add Drive API) —
Drive.About.getlives there. - A Gmail account to send from — the script uses
GmailAppunder your authorisation. - The address that should receive the warning, set in
ALERT_RECIPIENTbelow.
The script
// Where the warning email is sent.
const ALERT_RECIPIENT = '[email protected]';
// Percentage of quota that triggers a warning.
const WARN_THRESHOLD_PCT = 80;
// Bytes in a gigabyte, for readable figures in the email.
const BYTES_PER_GB = 1024 * 1024 * 1024;
/**
* Checks Drive storage usage and emails a warning if it has
* crossed WARN_THRESHOLD_PCT. Designed to run on a daily trigger.
*/
function checkQuota() {
// 1. Ask the Drive API for the storage quota figures.
const about = Drive.About.get({ fields: 'storageQuota' });
const limit = parseInt(about.storageQuota.limit, 10);
const used = parseInt(about.storageQuota.usage, 10);
// 2. Some accounts (e.g. pooled storage) report no fixed limit.
if (!limit) {
Logger.log('No fixed storage limit reported — nothing to check.');
return;
}
// 3. Work out how full the account is.
const pct = (used / limit) * 100;
// 4. Below the threshold, do nothing — no email, no noise.
if (pct < WARN_THRESHOLD_PCT) {
Logger.log('Drive at ' + pct.toFixed(1) + '% — under threshold.');
return;
}
// 5. Over the threshold: send a plain-spoken warning.
GmailApp.sendEmail(
ALERT_RECIPIENT,
`Drive at ${pct.toFixed(1)}% capacity`,
`Used ${(used / BYTES_PER_GB).toFixed(1)}GB of ` +
`${(limit / BYTES_PER_GB).toFixed(1)}GB.\n\n` +
`Clear some space or upgrade storage before uploads start failing.`
);
Logger.log('Warning sent — Drive at ' + pct.toFixed(1) + '%.');
}
How it works
checkQuotacallsDrive.About.getand asks only for thestorageQuotafield, keeping the request small.- It parses the
limitandusagevalues, which the API returns as strings of bytes. - If
limitis empty — some Workspace accounts use pooled storage with no per-user cap — it logs a note and stops, since there is nothing to measure. - It divides usage by limit to get a percentage.
- If that is under
WARN_THRESHOLD_PCT, it logs the figure and exits quietly — no email on a normal day. - If it is at or over the threshold, it emails
ALERT_RECIPIENTwith the percentage and the used-of-total figure in gigabytes, plus a one-line nudge.
Example run
On a day when the account is comfortable, the log reads:
Drive at 62.4% — under threshold.
No email is sent. When usage climbs past 80%, the recipient gets:
Subject: Drive at 83.7% capacity
Used 12.6GB of 15.0GB.
Clear some space or upgrade storage before uploads start failing.
Trigger it
Storage fills gradually, so a daily check is plenty:
- In the Apps Script editor, open the Triggers panel (the clock icon).
- Click Add Trigger.
- Choose
checkQuota, event source Time-driven, type Day timer, and pick an early-morning hour. - Save. Approve the authorisation prompt the first time it runs.
Watch out for
- The script warns once per day, every day, while usage stays above the
threshold — so a busy account can produce a steady drip of emails until
someone clears space. That repetition is intentional pressure, but raise
WARN_THRESHOLD_PCTor send only on first crossing if it grates. Drive.About.getreports the quota for the account running the script, not for a whole domain. For organisation-wide storage, use the Admin SDK instead.- Pooled-storage Workspace accounts may report no
limit. The guard handles that gracefully, but it also means this script cannot warn those accounts — monitor pooled storage from the Admin console. - Trash still counts against quota until it is emptied. If the warning fires and usage looks wrong, empty the trash before buying more storage.
Related
Detect and report broken file shortcuts
Find Drive shortcuts in Northwind folders pointing at deleted or inaccessible files.
Updated Dec 3, 2025
Build a Drive cleanup recommendation report
Suggest what Northwind can delete or archive — large, stale, duplicate, or untouched files.
Updated Nov 21, 2025
Generate a folder-level changelog
Track additions and deletions in a Northwind folder over time — a written history.
Updated Nov 5, 2025
Track contract expiry from Drive files
Read expiry dates out of Northwind contract Docs and warn before renewals.
Updated Oct 28, 2025
Enforce file naming and tagging governance
Flag Northwind files that don't match required naming or tagging conventions.
Updated Oct 16, 2025