Files
GoogleDriveManagement/wiki/Users-Drive-Cleanup.md
Ross Scroggs 0290f0d0ce
Some checks failed
Push wiki / pushwiki (push) Has been cancelled
Build and test GAM / build (false, build, 1, Build Intel Ubuntu Jammy, ubuntu-22.04) (push) Has been cancelled
Build and test GAM / build (false, build, 10, Build x86_64 macOS 15, macos-15-intel) (push) Has been cancelled
Build and test GAM / build (false, build, 11, Build Arm MacOS 26, macos-26) (push) Has been cancelled
Build and test GAM / build (false, build, 12, Build Intel Windows, windows-2025) (push) Has been cancelled
Build and test GAM / build (false, build, 13, Build Arm Windows, windows-11-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 2, Build Intel Ubuntu Noble, ubuntu-24.04) (push) Has been cancelled
Build and test GAM / build (false, build, 3, Build Arm Ubuntu Noble, ubuntu-24.04-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 4, Build Arm Ubuntu Jammy, ubuntu-22.04-arm) (push) Has been cancelled
Build and test GAM / build (false, build, 5, Build Intel StaticX Legacy, ubuntu-22.04, yes) (push) Has been cancelled
Build and test GAM / build (false, build, 6, Build Arm StaticX Legacy, ubuntu-22.04-arm, yes) (push) Has been cancelled
Build and test GAM / build (false, build, 8, Build Arm MacOS 14, macos-14) (push) Has been cancelled
Build and test GAM / build (false, build, 9, Build Arm MacOS 15, macos-15) (push) Has been cancelled
Build and test GAM / build (false, test, 14, Test Python 3.10, ubuntu-24.04, 3.10) (push) Has been cancelled
Build and test GAM / build (false, test, 15, Test Python 3.11, ubuntu-24.04, 3.11) (push) Has been cancelled
Build and test GAM / build (false, test, 16, Test Python 3.12, ubuntu-24.04, 3.12) (push) Has been cancelled
Build and test GAM / build (false, test, 17, Test Python 3.15-dev, ubuntu-24.04, 3.15-dev) (push) Has been cancelled
Build and test GAM / build (true, test, 18, Test Python 3.14 freethread, ubuntu-24.04, 3.14) (push) Has been cancelled
Build and test GAM / merge (push) Has been cancelled
Build and test GAM / publish (push) Has been cancelled
Check for Google Root CA Updates / check-certs (push) Has been cancelled
Replace teamdrive with shareddrive
2026-02-10 21:31:07 -08:00

6.3 KiB

Users - Drive - Cleanup

API documentation

Definitions

<SharedDriveID> ::= <String>
<SharedDriveName> ::= <String>
<SharedDriveEntity> ::=
        <SharedDriveID>|(shareddriveid <SharedDriveID>)|(shareddriveid:<SharedDriveID>)|
        (shareddrive <SharedDriveName>)|(shareddrive:<SharedDriveName>)

Display empty folders

gam <UserTypeEntity> print emptydrivefolders [todrive <ToDriveAttribute>*]
        [select <DriveFileEntity>]
        [pathdelimiter <Character>]

By default, empty folders on My Drive are displayed. Use select <DriveFileEntity> to select a Shared Drive or an alternate starting point folder on My Drive or a Shared Drive.

By default, folder path components are separated by /; use pathdelimiter <Character> to use <Character> as the separator.

Delete empty folders

gam <UserTypeEntity> delete emptydrivefolders
        [select <DriveFileEntity>]
        [<SharedDriveEntity>]
        [pathdelimiter <Character>]

By default, empty folders on My Drive are deleted(purged). Use select <DriveFileEntity> to select a Shared Drive or an alternate starting point folder on My Drive or a Shared Drive.

By default, folder path components are separated by /; use pathdelimiter <Character> to use <Character> as the separator.

Empty the trash on My Drive

gam <UserTypeEntity> empty drivetrash

Empty the trash on a Shared Drive

gam <UserTypeEntity> empty drivetrash <SharedDriveEntity>

Delete contents of My Drive

The following commands will delete the contents of a user's My Drive.

This is not reversible, Think before proceeding.

Method 1

  • Generate a complete list of files/folders that a user owns; this gives you a record of the files/folders that will be deleted.
  • This list may be quite large.
  • Delete the top level files/folders; orphans will be deleted.

Show current drive usage.

gam redirect stdout ./DrivefileUsage.txt user user@domain.com show drivesettings

Generate an initial list of files.

gam redirect csv ./InitialFileList.csv user user@domain.com print filelist fields id,name,mimetype,basicpermissions,parents fullpath showdepth orderby name

Purge top level files/folders; includes orphans.

gam config csv_input_row_filter "depth:count=0" redirect stdout ./PurgeTopLevelFilesFolders.txt multiprocess redirect stderr stdout csv ./InitialFileList.csv gam user "~Owner" purge drivefile "~id"

Generate list of remaining files/folders; this list should be empty; investigate if not.

gam redirect csv ./FinalFileList.csv user user@domain.com print filelist fields id,name,mimetype,basicpermissions,parents fullpath showdepth orderby name

Show updated drive usage.

gam redirect stdout ./DrivefileUsage.txt append user user@domain.com show drivesettings

Method 2

  • Generate a list of top level files/folders that a user owns.
  • Delete them; orphans are not included
  • Generate a list of remaining file/folders (orphans).
  • Delete them.

Show current drive usage.

gam redirect stdout ./DrivefileUsage.txt user user@domain.com show drivesettings

Get list of top level files/folders.

gam redirect csv ./TopLevelFilesFolders.csv user user@domain.com print filelist select rootid fields id,name,mimetype depth 0

Purge top level files/folders.

gam redirect stdout ./PurgeTopLevelFilesFolders.txt multiprocess redirect stderr stdout csv ./TopLevelFilesFolders.csv gam user "~Owner" purge drivefile "~id"

Get list of remaining files/folders; this list will typically be empty but will list orphans if they exist.

gam redirect csv ./OrphanFilesFolders.csv user user@domain.com print filelist fields id,name,mimetype,parents fullpath showdepth

Purge top level orphan files/folders; sub files/folders will also be deleted.

gam config csv_input_row_filter "depth:count=0" redirect stdout ./PurgeOrphanFilesFolders.txt multiprocess redirect stderr stdout csv ./OrphanFilesFolders.csv gam user "~Owner" purge drivefile "~id"

Generate list of remaining files/folders; this list should be empty; investigate if not.

gam redirect csv ./FinalFileList.csv user user@domain.com print filelist fields id,name,mimetype,basicpermissions,parents fullpath showdepth orderby name

Show updated drive usage.

gam redirect stdout ./DrivefileUsage.txt append user user@domain.com show drivesettings

Method 3

  • Generate a list of top level files/folders that a user owns.
  • Delete them; orphans are not included
  • Generate a list of remaining file/folders (orphans).
  • Delete them.

Show current drive usage.

gam redirect stdout ./DrivefileUsage.txt user user@domain.com show drivesettings

Get list of top level files/folders if desired.

gam redirect csv ./TopLevelFilesFolders.csv user user@domain.com print filelist my_top_items fields id,name,mimetype

Purge top level files/folders.

gam redirect stdout ./PurgeTopLevelFilesFolders.txt redirect stderr stdout user user@domain.com purge drivefile my_top_items

Get list of remaining files/folders; this list will typically be empty but will list orphans if they exist.

gam redirect csv ./OrphanFilesFolders.csv user user@domain.com print filelist fields id,name,mimetype,parents fullpath showdepth

Purge top level orphan files/folders; sub files/folders will also be deleted.

gam config csv_input_row_filter "depth:count=0" redirect stdout ./PurgeOrphanFilesFolders.txt multiprocess redirect stderr stdout csv ./OrphanFilesFolders.csv gam user "~Owner" purge drivefile "~id"

Generate list of remaining files/folders; this list should be empty; investigate if not.

gam redirect csv ./FinalFileList.csv user user@domain.com print filelist fields id,name,mimetype,basicpermissions,parents fullpath showdepth orderby name

Show updated drive usage.

gam redirect stdout ./DrivefileUsage.txt append user user@domain.com show drivesettings