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
You set your Google Drive domain to connect as an admin.
See Connect as admin to learn more about how you can set up your Google workplace to connect as an admin.
Your OneDrives are provisioned (you can automate this process with the Get-OneDriveURL cmdlet if needed).
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:
Download a list of all your Google Drive user emails as a CSV.
Open the CSV file.
Edit the file to keep only one column with the Google Drive email addresses.
Insert a header row.
Name the first column GOOGLEDRIVEEMAIL.
Open ShareGate Migrate.
Select All reports from the sidebar.
Click Create custom report.
Select OneDrive for Business as your object type.
Click Continue without saving.
Select your tenant.
Click Next.
Toggle off Use local cache.
Click Run now.
Select all OneDrive for Business accounts using the checkmark at the top of the list.
Click Edit in the Quick actions menu.
Select Add administrators in the Transformations dropdown.
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 Export in the top right corner.
Save the file on your drive, and open it.
Replace the Site address header with ONEDRIVEURL.
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.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 useforeach
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
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 can find them in Tasks. You can also export them with Export-Report in your script.
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 learn more about using copy options in PowerShell, see Copy options in PowerShell.