Extract metadata
Extract metadata
This script extracts metadata details for all the files and folders in any Box folder and saves the result in a CSV spreadsheet for each metadata template.
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 Setup with OAuth 2.0 guide.
Configure the script
-
Clone the
boxcli
GitHub repository or download the files fromexamples
directory.git clone https://github.com/box/boxcli.git
-
Specify the
folderID
anduserID
parameters to tell the script which folder to scan, and who is the user running the script.[string]$FolderID = "", [string]$UserID = "",
If you don't want to specify the parameters directly in the script, you can either pass them as flags or allow the script to prompt you to enter them. A sample command with flags looks as follows:
./Metadata-extraction.ps1 -folderId 123456789 -userId 123456789
Run the script
-
Change the directory to the folder containing the script. In this example, it is the
Metadata Extraction
folder.rvb@lab:~/box-cli/examples/Metadata Extraction$ pwsh PowerShell 7.2.4 Copyright (c) Microsoft Corporation. https://aka.ms/powershell Type 'help' to get help. PS /home/rvb/box-cli/examples/Metadata Extraction>
-
Run the script.
./Metadata-extraction.ps1 -folderId 123456789 -userId 123456789
When the script finishes, you will see the following output or a similar one.
Pulling data from Folder ID: 173961139760 metadata as user ID: 20718545815 Reading Item ID: 1016853559790 Metadata saved to: MetadataTemplate_properties.csv
Logging
Logs are stored in a logs
folder located in the main folder.
You have access to these log files:
Metadata-extraction_all.txt
that contains all log entries.Metadata-extraction_errors.txt
that contains only errors.