Use PowerShell to automate your Box.com to OneDrive for Business migration.
Note: You can migrate the content of your user's root folder in Box.com, but not the folder itself. If you want to migrate the Box.com content in a separate folder in OneDrive for Business, you will have to create that destination folder first.
Index
Prerequisites
-
Global Administrator or SharePoint Administrator permissions required.
-
Your OneDrives have been provisioned.
- This can be automated with the Get-OneDriveURL cmdlet.
Note: For a OneDrive migration the required permission is site collection administrator. The script in this article has commands to add site collection administrator permissions at the beginning of a OneDrive migration and to remove the permissions after it is completed. You need Global Administrator or SharePoint Administrator permissions for the commands to work.
Create your script
Copy and paste the following script in the PowerShell application of your choice.
Import-Module Sharegate
$box = Connect-Box -Email admin@enterprise.com -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 Add-SiteCollectionAdministrator -Site $dstSite $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 by your Box.com admin email.
- $myusername: Replace "myusername" by your Microsoft 365 account user name.
- $mypassword: Replace "mypassword" by 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: If you need to change the authentication method, you will find how to do it in the Connect Site article.
- Add-SiteCollectionAdministrator and Remove-SiteCollectionAdministrator: Adds your user account as site collection administrator before your migration, and removes it after.
Run your script once it's properly adjusted and tested.
Notes:
- To migrate your documents to a new folder in your OneDrives, you must create the folder beforehand.
- Migration reports are automatically generated, and you will be able to find them in Tasks. You can also export the reports in your script with Export-Report.
- You can schedule your migration using PowerShell to run it off-hours and optimize performance.
- To perform an incremental migration, check the the Incremental update using PowerShell article.
Comments
0 comments
Please sign in to leave a comment.