You cannot directly provision a new folder in your OneDrives when you run one of our PowerShell scripts to copy content to many OneDrives.
With this guide, you can provision a new folder in your OneDrives before running your migration script.
Index
Prerequisites
Your OneDrives have been provisioned (this can be automated with the Get-OneDriveURL cmdlet)
You are connected to your Microsoft 365 admin center in Explorer.
Note: You need to be site collection admin on each OneDrive, even if you have higher admin privileges. In step (12) below, you will use SharePoint admin or global admin permissions to apply site collection admin permissions needed to create a folder in each OneDrive. We do not go through the process of removing the site collection admin permissions in this guide.
Script preparation
Create a folder on your local drive and a CSV list of all your OneDrives with the following steps:
On your local drive, create a new folder.
Name the folder as per your preference in your OneDrives (e.g., C:\Migrated data).
Note of the path of the folder.
In ShareGate Migrate, go to All reports.
Click Create custom report in the top right corner.
Select OneDrive for Business as your object type.
Click Continue without saving.
Select your tenant.
Click 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 get back to your report results.
Click Export in the top right corner.
Save the file on your drive.
Open the report in Excel.
Add the title ONEDRIVEURL to the second column.
Save this new file as a CSV on your drive (i.e. C:\foldermigration.csv).
Note the path of the CSV file.
Tip: You can reuse that same CSV list for your OneDrive migration.
Create your script
Copy and paste the following script into the PowerShell application of your choice.
$csvFile = "C:\foldermigration.csv"$table = Import-Csv $csvFile -Delimiter ","$MyPassword = ConvertTo-SecureString 'My password' -AsPlainText -Force$MyUsername = "My username"Set-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 Import-Document -SourceFilePath "C:\Migrated data" -DestinationList $dstList}
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).
$MyPassword and $MyUsername: Replace 'My password' and "My username" with your Microsoft 365 credentials.
Connect-site: The command to connect to a SharePoint site. If you need to change the authentication method, see Connect Site. To use Browser authentication, see Use credentials from a previous browser connection.
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.
-SourceFilePath: Replace "C:\Migrated data" with the folder path you created in step (2).
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 is properly adjusted and tested.
Migrate content to your new folders
To migrate your content to the new OneDrive folders, you must add -DestinationFolder "folder name"
(replace folder name
with the name of your folder) to the copy line of your OneDrive migration script.
The copy line of your migration script should look like this:
Import-Document -SourceFolder $row.DIRECTORY -DestinationList $dstList -DestinationFolder "Migrated data"