Use PowerShell to automate your Google Drive to OneDrive for Business migration.
Index
Prerequisites
-
Global Administrator or SharePoint Administrator permissions are required.
-
Your Google drive domain is set to work in Administrator Mode.
-
Your OneDrives have been provisioned (this can be automated with the Get-OneDriveURL cmdlet).
Note: You must be site collection admin on each OneDrive, even if you have higher admin privileges. In step (15) below, 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 Google Drive.
How-to
Tip: To migrate your documents to a new folder in your OneDrives, see Walkthrough - Migrate to a new OneDrive folder in PowerShell.
Create a CSV guide for your migration
- Download a list of all your Google Drive user emails as a CSV.
- Open the CSV file generated from Google Drive.
- Edit the file so you only have one column with your user's Google Drive email addresses.
- Insert a new row at the top for the header.
- Name the first column GOOGLEDRIVEEMAIL.
- Open the ShareGate migration tool.
- Go to All reports.
- Click on Create custom report in the top right corner.
- Select OneDrive for Business as your object type.
- Click Continue without saving.
- Select your tenant.
- Click on Run.
- Select all your OneDrives with the checkmark box at top of the list.
- Click Edit in the Quick actions menu.
- Select Add administrators in the Transformations dropdown.
- Search and add your account in the Select user or group field that appears.
- Click Apply.
- Click Back two times to go back to your report results.
- Click on Export in the top right corner.
- Save the file on your drive, and open it.
- Replace the Site address header with ONEDRIVEURL.
- Combine the two spreadsheets so that each directory corresponds to the correct URL in your rows.
Note: If sorting alphabetically doesn't work, you can reorganize your data manually or you can look for a solution with Excel macros or PowerShell. - Save this new file as a CSV on your drive.
Create your script
Copy and paste the following script into the PowerShell application of your choice.
Import-Module Sharegate
$csvFile = "C:\MigrationPlanning\onedrivemigration.csv" $table = Import-Csv $csvFile -Delimiter "," $googleDrive= Connect-GoogleDrive -Email admin@mycompany.com -Admin
$mypassword = ConvertTo-SecureString 'mypassword' -AsPlainText -Force Set-Variable dstSite, dstList foreach ($row in $table) { Clear-Variable dstSite Clear-Variable dstList $dstSite = Connect-Site -Url $row.ONEDRIVEURL -Username "myusername" -Password $mypassword $dstList = Get-List -Name Documents -Site $dstSite Import-GoogleDriveDocument -GoogleDrive $googleDrive -SourceFolder $row.GOOGLEDRIVEEMAIL -SourceView "MyDocuments" -DestinationList $dstList
Remove-SiteCollectionAdministrator -Site $dstSite }
Adjust your script so that it will work for you. Here are a few guidelines:
- $csvFile: Adjust the path so that it points to the CSV file you saved before.
- $table: The delimiter is the symbol your CSV uses to separate your items in a row. Make sure your script uses the same delimiter as your file (a quick way to verify this is by opening the CSV with Notepad).
- $googleDrive: Replace the email with your Google Drive admin email. For more information, see Connect Google Drive.
- $mypassword: Replace 'mypassword' with your Microsoft 365 admin account password.
- $dstSite: Replace "myusername" with your Microsoft 365 admin account user name.
- Connect-site: The command to connect to a SharePoint site. If you need to change the authentication method, see Connect Site.
- Set-variable and Clear-Variable: These commands help prevent an issue where a connection failure can cause your data to end up in the wrong OneDrive.
- foreach: We use foreach to loop through the values in your CSV file. You can find more about it here.
- Remove-SiteCollectionAdministrator: Removes your user account as site collection administrator on the OneDrives after each Google Drive migration. For more information, see Remove Site Collection Administrator.
Run your script once it's properly adjusted and tested.
Considerations
- To use Browser authentication for your SharePoint site connection (Connect-Site), see Use credentials from a previous browser connection.
- 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, see the Incremental update using PowerShell article.
- To replicate the copy options from the migration tool, see Replicate copy options.