Pages

Tuesday, 7 April 2020

Bulk change ownership of Google Drive items

The following Google Apps Script is designed to bulk transfer ownership of Google Drive files/folders by iterating through them. It gets the current owner and compares that to the new designated owner before making the change. This particular example will retain the previous owner as an editor of the item.
Screenshot of transfer tool requirements
Screenshot of transfer tool requirements

A 'while' loop is used to cycle through and 'getFiles' in the first instance. From here we can get the email address of the current owner:
var currentFileOwner = file.getOwner().getEmail();
Using an 'if' statement we can then look for a match with the current owner specified on the Welcome sheet and if one is found the new owner can be set:
if (currentFileOwner == currentOwner) {
   file.setOwner(newOwner);
}
The process can then be repeated for sub-folders ('getFolders') which at the end we pass this folder ID back into the Function (hence creating a loop).

Bulk change ownership of Google Drive items

No comments:

Post a comment