Walkthrough - Import Files to OneDrive for Business using PowerShell



  • Avatar
    Dorje McKinnon

    This is a useful start - what would be great is some other examples for other scenarios e.g. incremental update ?

  • Avatar

    Hello Dorje,

    Thank you so much for the feedback. It is a great idea - we are looking into ways we can improve our PowerShell documentation with more step-by-steps! In the meantime, we think the New Copy Settings and Incremental Update articles will help.

    Have a great day!

  • Avatar
    Ginkel van, Marcel

    I know it is possible to add a time filter with Sharepoint migration, but it also possible to add a time filter for onedrive migration within the Powershell script mentioned above?

  • Avatar

    Hello Marcel!

    Yes, you can, you'll want to use the New Property Template script. 


    $propertyTemplate = New-PropertyTemplate -AuthorsAndTimestamps -VersionHistory -Permissions -WebParts -NoLinkCorrection -FlattenFolders -VersionLimit 5 -CheckInAs Publish -ContentApproval SameAsCurrent - From YYYY-MM-DD -To YYYY-MM-DD

    Hope that helps!

  • Avatar
    Knibbe, Erik

    Hello Alex,

    We use this script to import the home-folders from our users to OneDrive for Business.

    But we want to skip certain folders inside the home-folders. So, for each home-folder I cycle through all subfolders, selecting which to copy and which not. Then I use this line:

    $Result = Import-Document -SourceFolder "$SourcePath" -DestinationList $DstList -DestinationFolder "$DstFolder" -CopySettings $CopySettings -InsaneMode

    As you can see I added the option -DestinationFolder "$DstFolder"

    This returns the message "The folder X/ does not exist in the destination."

    That's correct, but it has to be created. Unfortunately, I didn't find an option to force that.

    So, my question is: Is there an option to create a folder that doesn't exist in the destination?

    Thanks in advance for your answer!

    Erik Knibbe


  • Avatar

    Hey Erik!

    We are not aware of an option for that! If you do end up finding a workaround, please feel free to share it.


  • Avatar
    Amit Patel (Edited )

    Hello Erik

    Did you ever find a solution for this (to create a new folder for each user)?  It looks like SPMT provided by Microsoft has the ability to create folder on the fly during the migration.  I ran into some speed issues with that so have started to look at ShareGate but I'm surprised that ShareGate doesn't natively support this.

    One way I found (probably not the most elegant) is by using the SharePoint online module:

    Install-Module SharePointPnPPowerShellOnline

    $mypassword = ConvertTo-SecureString "Admin Pwd" -AsPlainText -Force
    $mycreds = New-Object System.Management.Automation.PSCredential ("Admin User", $mypassword)
    Connect-PnPOnline -Url https://ORDCODE-my.sharepoint.com/personal/user_1_domain_com/ -Credentials $mycreds
    Add-PnPFolder -name NewFOlder -folder "Documents"




  • Avatar
    Knibbe, Erik

    Hello Amit,

    Thanks for your answer!

    We didn't found a solution. Our dirty work-arround is to copy all folders, en tell the users that they can safely remove the special folders that aren't used. ;-)

    Maybe the SharePoint module would have worked, but for now we already started the migration.



Please sign in to leave a comment.