Report inactive users
Report inactive users
This script generates a CSV file with a list of users who have been inactive for a number of days. It performs the following steps:
-
Looks for the users who have the role
user
. - Uses Box Events to check if the user performed any actions
for a specified number of days. The default list of event types includes:LOGIN
,UPLOAD
,COPY
,MOVE
,PREVIEW
,DOWNLOAD
,EDIT
,DELETE
,UNDELETE
,LOCK
,UNLOCK
,NEW_USER
. You can modify this list in the script settings. - Adds users who didn't perform any actions to a
.csv
file with inactive users. You can use this file as input for other scripts, for example to deprovision users.
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 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 fromexamples
directory.git clone https://github.com/box/boxcli.git
-
Set the number of days you want the script to scan for user events. If you don't specify this value or leave the default, the script will prompt you to enter it.
$daysInactive = "10"
-
(Optional) To change the report output file name, define the
ReportOutputFile
parameter.$ReportOutputFile = $ReportName + ".csv"
-
(Optional) To change event types, define the list for
eventType
parameter.$eventType = "LOGIN,UPLOAD,COPY,MOVE"
Run the script
Change the directory to the folder containing the script.
In this example, it is the Inactive Users Report
folder.
rvb@lab:~/box-cli/examples/Inactive Users Report$ pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.
https://aka.ms/powershell
Type 'help' to get help.
PS /home/rvb/box-cli/examples/Inactive Users Report>
Run the script.
./Inactive_Users_Report.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 the logs
folder located in the main folder.
You have access to these log files:
Inactive_Users_Report_all.txt
that contains all log entriesInactive_Users_Report_errors.txt
that contains only errors.