Tuesday, 30 July 2024

Change Drive ownership without email notification

The following Google Apps Script is designed to change ownership of a Google Drive item without sending the default email notification to the new owner. Please note this will only work within your organisation (i.e. on the same domain) and not between personal Google account (where consent is required by Google).

Snippet of code for changing Drive ownership
Snippet of code for changing Drive ownership


Enable Drive API

If you are not making a copy of the below file then ensure you enable the Drive API V2 in the Script Editor under Services.

You can find further details about the resource permissions on the Google Developers website.


Download

Change Drive ownership without email notification download (please use 'Overview' > 'Make a copy' for your own version).


/**
* Function to change ownership of a Google Drive item (within your organisation) without sending an email
* notification.
*
*
* DEVELOPED BY THE GIFT OF SCRIPT: https://www.pbainbridge.co.uk/
*/
function changeOwnership() {
// ID of the item to change ownership of
var itemID = "ENTER HERE";
// email address of the new owner
var newOwnerEmail = "ENTER HERE";
// create permission resource for sending to Drive API
var resource = {
// set the role to owner
role: "owner",
// choose from "user" or "group" (if using a Google Group)
type: 'user',
// provide the email address of the new owner
value: newOwnerEmail
};
// create optional arguments
var optionalArgs = {
// make compatible with Google Shared drives
supportsAllDrives: true,
// disable sending of automated notification email to new owner
sendNotificationEmails: false
};
// call Drive API to change ownership
Drive.Permissions.insert(resource, itemID, optionalArgs);
};

No comments:

Post a Comment