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 add a new folder in your OneDrives to copy your source files to before running your migration script.
Note: At the end of January 2026, Microsoft began deprecating the IDCRL cookie, meaning that only Browser and Modern authentication methods with the parameters -Browser and -ModernAuth will work in most Microsoft 365 tenants. To learn more about this change, see Important change to "Other user" authentication for Microsoft 365.
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 a 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 remove site collection admin permissions in this guide because this step is included in other PowerShell OneDrive migration guides.
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 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 the 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.
# Define the CSV file path
$csvFile = "C:\foldermigration.csv"
# Import the CSV file
$table = Import-Csv $csvFile -Delimiter ","
# Define the destination connection
$dstSiteConnection = Connect-Site -Url "https://destinationtenantname-my.sharepoint.com/" -ModernAuth
# Set variables for site and list operations
Set-Variable dstSite, dstList
# Loop through each row in the CSV
foreach ($row in $table) {
# Clear previous values of variables
Clear-Variable dstSite
Clear-Variable dstList
# Connect to the OneDrive site
$dstSite = Connect-Site -Url $row.ONEDRIVEURL -UseCredentialsFrom $dstSiteConnection
# Get the "Documents" list from the destination site
$dstList = Get-List -Name Documents -Site $dstSite
# Import documents from the source file path to the destination list
Import-Document -SourceFilePath "C:\Migrated data" -DestinationList $dstList
}
Adjust your script so it works 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 to open the CSV in Notepad).
$dstSiteConnection: Replace the URL with the root URL of your OneDrives in the destination tenant.
Connect-site: The command to connect to a SharePoint site. If you need to change the authentication method to Browser authentication, 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.
-SourceFilePath: Replace "C:\Migrated data" with the folder path you created in step (2).
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 documents from the source folder to the destination list and folder
Import-Document -SourceFolder $row.DIRECTORY -DestinationList $dstList -DestinationFolder "Migrated data"
