Manage groups and collaborations
Manage groups and collaborations
Script structure
This script uses Box CLI to create or update groups, add users to them, and finally to create collaborations between groups and folders. The script consists of two parts described in detail in the sections below. You can run them both or use the optional flags to decide which part to run.
Create or update groups
-
The script uses the
.csvfile you specify for theUserGroupAdditionPathparameter. The file lists group names and user emails. When creating the file, you can use the same group name for several users, and assign one user to several groups. For example:GroupNameUserEmailGroup1 ManagedUser1@test.comGroup1 ManagedUser2@test.comGroup2 ManagedUser3@test.comGroup3 ManagedUser1@test.com -
If the group doesn't exist, the script creates it. If it does exist, the script can update the entries based on the provided data.
Create or update collaborations
-
The script uses the
.csvfile you specify for theCollaborationsCreationPathparameter. The file lists group names, folder IDs, and collaboration roles. -
For each row, the script checks if a group exists and if it's not already added as a collaborator to the corresponding folder. For example:
GroupNameFolderIdCollaborationRoleGroup1 1111111 editor Group2 1111111 viewer_uploader Group2 2222222 viewer Group3 1111111 viewer_uploader -
If both of these conditions are met, the script assigns the group to a folder using the role defined in the
CollaborationRolecolumn. Also, if a group already exists, but theCollaborationRolechanged, the script will update it if you pass the-UpdateExistingCollabsflag when running the script.
Prerequisites
Windows
Install the latest version of dotnet core.
MacOS & Linux
Install PowerShell. Run the pwsh command to test the installation.
pwsh
Depending on the directory you are running the command in, the output may differ. For example:
PowerShell 7.2.5
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /Users/user/repos/boxcli/examples>
Box CLI
To use the script, you will need the Box CLI installed and configured. You can get this done by going through our quick start guide. The user you use to login with should be the main Box admin or co-admin.
Configure the script
-
Clone the
boxcliGitHub repository and cd into this example's folder or download the files fromexamplesdirectory.git clone https://github.com/box/boxcli.git boxcli cd boxcli/examples/Mass\ Groups\ \&\ Collaborations\ Update/ -
Set the path to the
.csvfile with the list of groups and user emails.$UserGroupAdditionPath = "./User_Group_Addition.csv"UserEmailis the primary email address for the user in Box.GroupNameis the name of the group.
-
Set your own path to the
.csvfile with the list groups and user emails.$CollaborationsCreationPath = "./Collaborations_Creation.csv"GroupNameis name of the group the script will add as a collaborator to the folder.FolderIdis the folder ID the collaborator will be added to.CollaborationRoleis the name of the role used when creating a collaboration.
You can configure the available roles by setting the
AvailableCollaborationRolesparameter:$AvailableCollaborationRoles = @("editor", "viewer", "previewer", "uploader", "previewer_uploader", "viewer_uploader", "co-owner")
Run the script
-
Run the Powershell command.
pwsh -
Run the script.
./Mass_Groups_Collabs_Update.ps1
Optional flags
You can use flags to run run or skip specific parts of the script.
-
If a group already is set as a collaborator for a specific folder but with a role other than defined in the .
csvfile, the script will inform you about it. It will not make any changes to an existing collaboration. If you want to update an existing collaboration with role defined in.csvfile, set an additional-UpdateExistingCollabsflag when running the script.Mass_Groups_Collabs_Update.ps1 -UpdateExistingCollabs -
To update groups without creating collaborations, add the
-SkipCollabsCreationboolean flag when running the script:Mass_Groups_Collabs_Update.ps1 -SkipCollabsCreation -
To create collaborations without any group updates, add the
-SkipGroupsUpdateboolean flag when running the script:Mass_Groups_Collabs_Update.ps1 -SkipGroupsUpdate
Logging
Logs are stored in the logs folder located in the main folder.
You have access to these log files:
Mass_Groups_Collabs_Update_all.txtthat contains all log entriesMass_Groups_Collabs_Update_errors.txtthat contains only errors.