Join the first BoxWorks Hackathon for Good - customers, partners, and the developer community are welcome to participate in the 48 hour Hack to benefit The Nature Conservancy.

Learn more and register!

Deprovision users and archive folders

Guides CLI CLI sample scripts Deprovision users and archive folders
Edit this page

Deprovision users and archive folders

This script allows you to deprovision and delete a list of users. It performs the following steps:

  1. Transfers the user content to the current admin user's root folder under Employee Archive.
  2. Deletes the user.

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> 

If you encounter issues make sure you installed both dotnet core and PowerShell.

Box application

To use the script, you will need a Box application with OAuth 2.0 authentication. If you don't have one, go to your developer console, and follow the guide Setup with OAuth 2.0.

Configure the script

Clone the boxcli GitHub repository or download the files from examples directory.

git clone https://github.com/box/boxcli.git

Set your own path to the CSV file with the list of employees.

$EmployeeList = "./Employees_to_delete.csv"

Customize the Employees_to_delete.csv input file of employee accounts you want to delete by providing their email addresses. For example:

name,email
Managed User 1,ManagedUser1@test.com

(Optional) To skip transfer of user content before deleting the user, set the TransferContent parameter to N.

$TransferContent = "N"

(Optional) Change the EmployeeArchiveFolderName to any name of your choice.

$EmployeeArchiveFolderName = "Employee Archive"

Run the script

Change the directory to the folder containing the script. In this example, it is the User Deprovisioning folder.

rvb@lab:~/box-cli/examples/User Deprovisioning$ pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.
  
PS /home/rvb/box-cli/examples/User Deprovisioning>

Run the script.

./Users_Deprovision.ps1

When the script run is completed, you will see the following output or a similar one.

Transfered employee content Managed User 1
with User ID: 19927131476 to Employee Archive Folder
Deleted user 19927131476
Deleted employee Managed User 1

Logging

Logs are stored in a logs folder located in the main folder. You have access to these log files:

  • Users_Deprovision_all.txt that contains all log entries
  • Users_Deprovision_errors.txt that contains only errors.

[employeelist]:[https://github.com/box/boxcli/blob/main/examples/User%20Deprovisioning/Users_Deprovision.ps1#L12