Skip to content

kylefernandadams/box-powershell-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Box PowerShell Example

This project provides an example PowerShell script to the following actions:

  • Get a specifc user from Box.
  • Query a Azure SQL database.
  • Automatically create a Box folder structure from values in the SQL result set.
  • Get a file from the local file system based on values in the SQL result set.
  • Upload a file from the local file system to Box.
  • Get the SHA1 file hash before and after the upload to Box and ensure they're the same.
  • Add metadata to the file uploaded to Box with values in the SQL result set.
  • Move the successfully processed file to a "processed" folder.

Installation Instructions

  1. Ensure that you're using a Box developer sandbox. You can sign up for a developer account here.
  2. Install the BoxCLI.
  3. Create a new metadata template.
  4. Clone or download the GitHub repository:
git clone https://github.com/kylefernandadams/box-powershell-example
  1. Modify following variables in the box-powershell-example.ps1 file.

    CAUTION: Do not store your DB credentials in plaintext for production purposes. Please follow your organization's security guidelines and best practices.

    It is possible to get a PSCredential object and store it in an encrypted file using an example like the following.

    Store Credentials: Get-Credential | Export-Clixml -Path C:\my\path\${env:USERNAME}_cred.xml

    Retrieve Credentials: $Credentials = Import-Clixml -Path C:\my\path\${env:USERNAME}_cred.xml

    Get Username: $User = $Credentials.Username

    Get Password: $Password = $Credentials.GetNetworkCredential().Password

    CAUTION...AGAIN: $Password is not encrypted at this point in time so you may want to leave it in the credential object so it stays encrypted in memory.

  2. Run the PowerShell script

.\box-powershell-example.ps1
  1. Example output
PS C:\powershell-demo> .\box-powershell-example.ps1
Found Box user: 385982796
Found sub folder with id: 48881865849 and name: 2402
Found folder with id: 48883422413 and name: 2018-04-23
Found file: sample-video-4.mp4
Successfully uploaded file with id 289481833770 and name sample-video-4.mp4 and sha1: b768f76080c2a04434a0931582548913ee35a016
Found file hash before: B768F76080C2A04434A0931582548913EE35A016 and after: b768f76080c2a04434a0931582548913ee35a016
File hashes match! Continue adding metadata...
Added box metadata: {   "siteId": "2402",   "videoTitle": "sample-video-4.mp4",   "videoLength": "0:47",   "videoLatitude": "31.766885",   "videoLongitude": "-106.451048",   "deviceSerialNumber": "5vghdw9usdmmn3h",   "deviceName": "Pam Beesley Axon Body 2",   "deviceFirmwareVersion": "5.1",   "deviceModelNumber": "AxonBody2",   "deviceWarrantyDate": "2020-04-30T09:00:00-04:00",   "$type": "boxCliSample-8b4b8e13-5f9b-4ae6-82e7-25d1ec7ef446",   "$parent": "file_289481833770",   "$id": "7e41f8ef-2cb2-4819-aba7-5de1f5e8e8db",   "$version": 0,   "$typeVersion": 0,   "$template": "boxCliSample",   "$scope": "enterprise_5105484" }

Disclaimer

The script provided in this project is an open source example and should not be treated as an officially supported product. Use at your own risk. If you encounter any problems, please log an issue.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

About

Example PowerShell script that leverages the BoxCLI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published