Skip to content

Instantly share code, notes, and snippets.

@TomTasche
Last active February 10, 2022 09:51
Show Gist options
  • Save TomTasche/4390e5732e4627fe8801a75cc8f91332 to your computer and use it in GitHub Desktop.
Save TomTasche/4390e5732e4627fe8801a75cc8f91332 to your computer and use it in GitHub Desktop.
Remove access for user from multiple files on Google Drive - https://blog.tomtasche.at/2018/02/remove-user-from-multiple-documents.html
function main() {
findSharedDocuments("[email protected]");
}
function findSharedDocuments(email) {
var files = DriveApp.searchFiles('("' + email + '" in readers OR "' + email + '" in writers) AND NOT ("' + email + '" in owners)');
var success = 0;
while (files.hasNext()) {
var file = files.next();
try {
file.revokePermissions(email);
success++;
} catch (e) {}
Logger.log("file: " + file.getName());
Logger.log("success: " + success);
}
var files = DriveApp.searchFolders('("' + email + '" in readers OR "' + email + '" in writers) AND NOT ("' + email + '" in owners)');
var success = 0;
while (files.hasNext()) {
var file = files.next();
try {
file.revokePermissions(email);
success++;
} catch (e) {}
Logger.log("file: " + file.getName());
Logger.log("success: " + success);
}
}
function findOwnedDocuments(email) {
var files = DriveApp.searchFiles('"' + email + '" in owners');
while (files.hasNext()) {
var file = files.next();
Logger.log(file.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment