Skip to main content
All CollectionsMigratePowerShellOneDrive migrations
Import from Box.com to OneDrive for Business with PowerShell
Import from Box.com to OneDrive for Business with PowerShell
Updated this week

Use PowerShell to automate your Box.com to OneDrive for Business migration.

Index

Prerequisites

Note: You need to be site collection admin on each OneDrive, even if you have higher admin privileges. You will use SharePoint admin or global admin permissions to apply site collection admin permissions on all your OneDrives. The PowerShell script will then remove the Site collection admin permissions as you migrate each Box.com account.

How-to

Tip: To migrate your documents to a new folder in your OneDrives, see Walkthrough - Migrate to a new OneDrive folder in PowerShell.

Assign yourself as site collection administrator on all your OneDrives

  1. Open ShareGate Migrate.

  2. Go to All reports.

  3. Click on Create custom report in the top right corner.

  4. Select OneDrive for Business as your object type.

  5. Click Continue without saving.

  6. Select your tenant.

  7. Click on Run.

  8. Select all your OneDrives with the checkmark box at top of the list.

  9. Click Edit in the Quick actions menu.

  10. Select Add administrators in the Transformations dropdown.

  11. Search and add your account in the Select user or group field that appears.

  12. Click Apply.

Create your script

Copy and paste the following script in the PowerShell application of your choice.

Import-Module Sharegate$box = Connect-Box -Email [email protected] -Admin
$users = Get-BoxUsers -Box $box$myusername = "myusername"$mypassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force$tenant = Connect-Site -Url https://mytenant-admin.sharepoint.com -Username $myusername -Password $mypassword
foreach ($user in $users) {
    If ($user.Status -ne 'inactive') {
        $dstSiteUrl = Get-OneDriveUrl -Tenant $tenant -Email $user.Email
        $dstSite = Connect-Site -Url $dstSiteUrl -Username $myusername -Password $mypassword
        $dstList = Get-List -Site $dstSite -name "Documents"
        Import-BoxDocument -Box $box -DestinationList $dstList -UserEmail $user.Email
        Remove-SiteCollectionAdministrator -Site $dstSite
    }
}

Adjust your script so that it will work for you. Here are a few guidelines:

  • $box: Replace the email with your Box.com admin email.

  • $myusername: Replace "myusername" with your Microsoft 365 account user name.

  • $mypassword: Replace 'mypassword' with your Microsoft 365 account password.

  • $tenant: Change the URL to match your tenant's admin center.

  • foreach: Used to loop through a set of values. In this case, all the commands between the foreach brackets will be repeated for each user in your Box.com account.

  • Connect-site: The command to connect to a SharePoint site. If you need to change the authentication method, see Connect Site.

  • Remove-SiteCollectionAdministrator: Removes your user account as site collection administrator on the OneDrive after its migration. For more information, see Remove Site Collection Administrator.

Run your script once it's properly adjusted and tested.

Considerations

Did this answer your question?