Files
GoogleDriveManagement/docs/Users-Drive-Cleanup.md
Ross Scroggs caddda2b1c
Some checks failed
Build and test GAM / build (Win64, build, 7, VC-WIN64A, windows-2022) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 2, linux-aarch64, [self-hosted linux arm64]) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 4, linux-aarch64, [self-hosted linux arm64], yes) (push) Has been cancelled
Build and test GAM / build (aarch64, build, 6, darwin64-arm64, macos-14) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 1, linux-x86_64, ubuntu-22.04) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 3, linux-x86_64, ubuntu-22.04, yes) (push) Has been cancelled
Build and test GAM / build (x86_64, build, 5, darwin64-x86_64, macos-13) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 10, ubuntu-24.04, 3.10) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 11, ubuntu-24.04, 3.11) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 8, ubuntu-24.04, 3.13) (push) Has been cancelled
Build and test GAM / build (x86_64, test, 9, ubuntu-24.04, 3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Check for Google Root CA Updates / check-apis (push) Has been cancelled
Build and test GAM / merge (push) Has been cancelled
Build and test GAM / publish (push) Has been cancelled
Integrate Wikis - Step 1
2024-10-06 09:02:31 -07:00

6.7 KiB

!# Users - Drive - Cleanup

API documentation

Definitions

<SharedDriveID> ::= <String>
<SharedDriveName> ::= <String>
<SharedDriveEntity> ::=
        <SharedDriveID>|(teamdriveid <SharedDriveID>)|(teamdriveid:<SharedDriveID>)|
        (teamdrive <SharedDriveName>)|(teamdrive:<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 version 6.22.14 and higher:

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

GAM version 6.22.13 and lower.

gam user user@domain.com show fileinfo root fields id
User: user@domain.com, Show 1 Drive File/Folder
  Drive Folder: My Drive (0AENlVEBUkz-hUkWXYZ)
    id: 0AENlVEBUkz-hUkWXYZ
gam redirect csv ./TopLevelFilesFolders.csv user user@domain.com print filelist select 0AENlVEBUkz-hUkWXYZ 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

  • GAM version 6.30.09 and higher
  • 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