Recursive Commands
While batch commands are extremely powerfull and versatile, they do require some “setup”.
You need to prepare your CSV (probably either via a spreadsheet application or a script) and think about your flag usage.
Recursive commands are a lot simpler to use and allow you to apply a command “recursively” to a bunch of objects.
Recursive subcommands can apply to one of two object types:
- Files (or folders) in Drive
- Users
Recursive File Commands
Recursive file commands apply an operation, such as granting a permission or copying a folder, recursively to all children of the referenced folder.
Exclude Specific Folders
All of the recursive file commands support the --excludeFolders
flag, which allows you to exlude specific folders (referenced by their fileId) from the command. You can either use the flag multiple times, or specify multiple values by separating them by comma (",").
Examples
“Move” a folder to a Shared Drive
WARNING: It is not possible to actually move a folder object to a Shared Drive via the Drive API as of this writing! What this will do is create a copy of the folder structure of the referenced folder and move all files from their source folders to the newly created copies, thus leaving the structure intact.
Any permissions granted on the oroginal folders will not be copied
The original folder structure will not be deleted at the source. You can do that manually after you have ensured that everything is ok!
gsm files move recursive --folderId <Id of the folder that should be moved> --parent <Id of the parent. Either a folder or a Shared Drive>
Copy a folder
gsm files move recursive --folderId <Id of the folder that should be moved> --parent <Id of the parent. Either a folder or a Shared Drive>
Any permissions granted on the oroginal folders will not be copied\
Transfer Ownership of an entire Drive Folder
WARNING: The Google Drive API requires you to send a notification when transfering ownership of an object. Please keep this in mind, when transferring ownership of a large folder!
gsm permissions create recursive --folderId <Id of the folder that should be transferred- --emailAddress <emailAddress of the the owner> --type user --role owner --transferOwnership --moveToNewOwnersRoot --sendNotificationEmail
Remove a user’s permissions on a folder
gsm permissions delete recursive --folderId <Id of the folder from which the permissions should be removed> --permissionId <permissionId of the user whose permissions should be removed>
Since a user’s permissionId will always be the same, it will be enough to look at one of the permissions that should be removed and supply that permissionId.
Recursive User Commands
Recursive user commands allow you to apply one operation to many users by specifying one or more organizational unit(s) and / or group(s).
- Organizational units are specified with the
--orgUnit
flag, where “/” is the root (so all users!) - Groups are specified with the
--groupEmail
flag Both flags can be used multiple times to specify more than one group and / or organizational unit and they can be combined. GSM will automatically get rid of duplicates. By supplying an organizational unit, GSM will apply the command to all users in that organizational unit and all sub OUs (thus “recursive”). By supplying a group, GSM will apply the command to all members of that group, including all nested group members.
Add all users in an organizational unit to a group
gsm members insert recursive --groupKey <email address of your group> --orgUnit <path of your orgUnit>
Sign out all users in an organizational unit
gsm users signOut recursive --orgUnit <path of your orgUnit>
(Un)Make everyone in an organizational unit an admin
gsm users makeAdmin recursive --orgUnit <path of your orgUnit>
To unmake (revoke Super Admin privileges)
gsm users makeAdmin recursive --orgUnit <path of your orgUnit> --unmake
Reset the password of everyone in a group
gsm users patch recursive --groupEmail <email address of your group> --password <new password>
Assign a license to everyone in an OU and group
gsm licenseAssignments insert recursive --orgUnit <path of your orgUnit> --groupEmail <email address of your group> --skuId <skuId>
SEE ALSO
- gsm - Command overview
- gsm files move recursive - Recursively moves a folder and its content to a new destination
- gsm files copy recursive - Recursively creates a copy of a folder and its content at a new destination
- gsm permissions create recursive - Recursively grant permissions on a folder and its content
- gsm members insert recursive - Add all users in the supplied OUs/groups to a group
- gsm users signOut recursive - Sign out all users in the supplied OUs/groups
- gsm users makeAdmin recursive - Grant / Remove the Super Admin privilege to every user in the supplied OUs/groups
- gsm users patch recursive - Apply updates to every user in the supplied OUs/groups
- gsm licenseAssignments insert recursive - Assign a license to every user in the supplied OUs/groups
- examples - See some examples
- scripting examples - Some examples on how to use GSM in scripts