Changing ownership of files in Google Drive via Google Apps Script

This was a fun little exercise in Google Apps Script to essentially transfer ownership of Google Drive files from one user to another.

Here’s a script that the old user should run to change ownership of those files to the new user:
ChangeFileFolderOwnership.js

And here’s a script that the new user user should run to remove the old user as editor from the newly changed-ownership files:
RemoveEditorFromDriveFiles.js

Note: You cannot use the file.removeEditor() command to remove yourself as an editor, so that actually has to be run from the new owner’s account.

Another Note: Just as when you change ownership or add editorship manually, scripting will also produce a ton of emails to the new editor/owner that you’ve add that person, so the new editor/owner may want to set up some temporary Gmail filters to mark those as read and put into the trash.


Posted

in

by

Comments

12 responses to “Changing ownership of files in Google Drive via Google Apps Script”

  1. Alex Avatar
    Alex

    For the ChangeFileFolderOwnership how can scope it down to specific folder instead of the entire drive?

  2. Jacques Talbot Avatar
    Jacques Talbot

    Hello Alan Siu,
    I assume this script works only for Google “native” files (as opposed to uploaded PDF, Office, jpg …), since there is this constraint in Google Drive. Is this correct ?
    Thanks and happy new year (could be better than 2020 😉

    1. alanysiu Avatar
      alanysiu

      I’m not sure, actually. Give it a try!

  3. Ujj Nath Avatar
    Ujj Nath

    I tried it but I have a paid google drive account and it worked.

  4. Lucia Hassell Avatar
    Lucia Hassell

    I am trying to change ownership of a set of files in Drive for a set of users. Meaning I want each of my students to become owners of different files. Any ideas?

    1. alanysiu Avatar
      alanysiu

      Sure. You can Frankenstein the scripts linked to in the blog post with this script:
      https://github.com/aysiu/GoogleAppsScripts/blob/main/SheetsToDocTemplateAndEmailMerge.js

  5. JULIO CESAR SOTO FUENTES Avatar
    JULIO CESAR SOTO FUENTES

    Is it possible it will make recursive?
    Folder and subfolder

    Thanks in advance.

    1. alanysiu Avatar
      alanysiu

      It’s not going based on folder. It’s going based on file owner and searching all of drive:
      https://github.com/aysiu/GoogleAppsScripts/blob/main/ChangeFileFolderOwnership.js#L7

  6. Hans A Avatar
    Hans A

    I tried the following command and it worked:
    sudo profiles renew -type enrollment
    I think you need to be on Big Sur or higher.

    1. BastienY Avatar
      BastienY

      Hey Hans, your solution seems utterly simple, but does it really work ? It seems to me the question here is to change ownership on several files from Google drive, whereas it seems to me that your solution would change ownership on a MacOS file, isn’t ? I’m sorry if i misunderstood..

  7. José G. Avatar

    Dearest Alanysiu, thanks for this scripts … all are very easy to read and useful.

    I have a question:

    I revised “changeFileFolderOwnership.js” and realized that “folders” are not considered. However, maybe the folders are “seen” like files and the script changes the ownership even when folders are involved.

    Am I right or I need to “frankestein” (great term :-)) your script to consider folders too?

    Best regards.

    José G.

Leave a Reply

Your email address will not be published. Required fields are marked *