Skip to main content
All CollectionsMigratePowerShellOneDrive migrations
Import Google Drive documents to OneDrive for Business with PowerShell
Import Google Drive documents to OneDrive for Business with PowerShell
Updated this week

This guide explains how to use PowerShell to automate the migration of files from Google My Drive to OneDrive for Business using the Import-GoogleDriveDocument command.

Tip: This guide focuses on migrating your files and folders to the root of the Documents library in OneDrive. To migrate your documents to a new folder, refer to the Walkthrough - Migrate to a new OneDrive folder in PowerShell.

Index

Prerequisites

Note: You must be a 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 remove the site collection admin permissions as you migrate each Google Drive.

How-to

Create a CSV guide for your migration

To automate the migration, you first need to create a CSV file that maps your Google Drives to your OneDrives:

  1. Download a list of all your Google Drive user emails as a CSV.

  2. Open the CSV file.

  3. Edit the file to keep only one column with the Google Drive email addresses.

  4. Insert a header row.

  5. Name the first column GOOGLEDRIVEEMAIL.

  6. Open ShareGate Migrate.

  7. Select All reports from the sidebar.

  8. Click Create custom report.

  9. Select OneDrive for Business as your object type.

  10. Click Continue without saving.

  11. Select your tenant.

  12. Click Next.

  13. Toggle off Use local cache.

  14. Click Run now.

  15. Select all OneDrive for Business accounts using the checkmark at the top of the list.

  16. Click Edit in the Quick actions menu.

  17. Select Add administrators in the Transformations dropdown.

  18. Add your account in the Select user or group field that appears.

  19. Click Apply.

  20. Click Back two times to go back to your report results.

  21. Click Export in the top right corner.

  22. Save the file on your drive, and open it.

  23. Replace the Site address header with ONEDRIVEURL.

  24. Combine this CSV with the Google Drive email CSV so that each Google Drive email matches the correct OneDrive for Business URL.
    โ€‹


    โ€‹Note: If sorting alphabetically doesn't work, you can reorganize your data manually or use Excel macros or PowerShell to find a solution.

  25. Save this new file as a CSV.

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 ","$connection = Connect-GoogleDrive -Email [email protected] -Admin$mypassword = ConvertTo-SecureString 'mypassword' -AsPlainText -ForceSet-Variable dstSite, dstListforeach ($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    $myDrive = Get-GoogleMyDrive -Connection $connection -Email $row.GOOGLEDRIVEEMAIL    Import-GoogleDriveDocument -Drive $myDrive -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 to point to the CSV file you saved before.

  • $table: The delimiter is the symbol your CSV uses to separate items in a row. Ensure your script uses the same delimiter as your file (a quick way to verify this is by opening the CSV with Notepad).

  • $connection: 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. To learn more about how to use foreach in your ShareGate PowerShell scripts, see Copy to and from multiple destinations with a foreach loop statement and a CSV file in PowerShell.

  • 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

Did this answer your question?