How to Copy Files from OneDrive to SharePoint Online?

Requirement: Copy files from OneDrive to SharePoint Online.

How to Copy Files from OneDrive for Business Sites to SharePoint Online?

If you’re using OneDrive for Business and SharePoint Online, there may be times when you need to copy files from OneDrive to SharePoint for various reasons, such as sharing with a team or for better collaboration. This can be done using the built-in “Copy to” feature in OneDrive, or by using third-party tools. We’ll show you how to easily copy files between these two services in this guide!

To copy files from OneDrive to SharePoint Online, do the following:

  1. Navigate to the OneDrive for Business site >> Select the files and folders to copy and click on the “Copy to” button in the toolbar.
    copy files from onedrive to sharepoint online
  2. This opens a panel to select a destination site. You’ll get a list of the frequent sites you have access to. Pick the destination site from the list. You can click the “Browse sites” and “Show more” buttons to load more sites.
    onedrive to sharepoint online
  3. When the site is selected, the next page in the wizard allows you to pick the library and folder. Once you select the document library or folder, click the “Copy here” button to start copying from OneDrive to the selected SharePoint Online site.
    copy files folders from onedrive for business to sharepoint online document library

Once the copy operation is completed, you’ll see a message saying copied items. Similarly, you can move data from OneDrive to SharePoint Online by clicking on the “Move to” button in the ribbon and following the rest of the above steps. Apart from the “Copy to” or “Move to” functions, You can also use the File Explorer copy-paste methods to copy files from OneDrive to SharePoint Online and vice versa.

PnP PowerShell to Copy Files from OneDrive to SharePoint

Make sure you set the parameters accordingly and have access to both source and target sites before running this script. Make sure the target library is already created.

# Parameters
$SourceSiteUrl = "" # URL of your OneDrive
$TargetSiteUrl = "" # URL of your target SharePoint site
$SourceLibraryName = "Documents" # Name of your document library in OneDrive
$TargetLibraryName = "Sal-OneDrive Backup" # Name of your target document library in SharePoint

#Connect to the source - OneDrive site
$SourceConn = Connect-PnPOnline -Url $SourceSiteUrl -Interactive -ReturnConnection
$SourceLibrary = Get-PnPList -Identity $SourceLibraryName -Connection $SourceConn

#Connect to the Target - SharePoint Online site
$TargetConn = Connect-PnPOnline -Url $TargetSiteUrl -Interactive -ReturnConnection
$TargetLibrary = Get-PnPList -Identity $TargetLibraryName -Connection $TargetConn
$TargetRootFolder = Get-PnPProperty -ClientObject $TargetLibrary -Property RootFolder

# Create Source Folder Structure on the Target
$SourceFolders = Get-PnPListItem -List $SourceLibrary -Connection $SourceConn  | Where { $_.FileSystemObjectType -eq "Folder"} 
ForEach ($Folder in $SourceFolders) {
    $SourceFolderSiteRelativePath = $Folder.FieldValues.FileRef.Replace($SourceLibrary.RootFolder.ServerRelativeUrl, [string]::Empty)
    $TargetFolderSiteRelativePath = Join-Path $TargetRootFolder.Name $SourceFolderSiteRelativePath
    #$SourceFolderSiteRelativePath.Replace($SourceLibrary.RootFolder.ServerRelativeUrl, [string]::Empty)
    Write-Host "Ensuring Folder at $TargetFolderSiteRelativePath" -ForegroundColor Green
    Resolve-PnPFolder -SiteRelativePath $TargetFolderSiteRelativePath | Out-Null

# Get files from the source library
$SourceFiles = Get-PnPListItem -List $SourceLibrary -Connection $SourceConn | Where { $_.FileSystemObjectType -eq "File"}

$Counter = 1
$TotalFiles = $SourceFiles.Count
# Copy files to the target library
ForEach ($File in $SourceFiles) {

    #Display Progress Bar
    Write-Progress -PercentComplete ($Counter/$TotalFiles*100) -Activity "Copying Files" -Status "Copying File $($file.FieldValues.FileRef) ($Counter of $TotalFiles)..."  

    #Get Source File
    $SourceFile = Get-PnPFile -Url $file.FieldValues.FileRef -Connection $SourceConn -AsFile -Path $Env:TEMP -Filename $File.FieldValues.FileLeafRef -Force

   #Upload File to the Target    
    $FilePath = Join-Path $Env:TEMP $File.FieldValues.FileLeafRef
    $SourceFileSiteRelativePath = $File.FieldValues.FileDirRef.Replace($SourceLibrary.RootFolder.ServerRelativeUrl, [string]::Empty)
    $TargetFolderSiteRelativePath = Join-Path $TargetRootFolder.Name $SourceFileSiteRelativePath
    Add-PnPFile -Path $FilePath -Folder $TargetFolderSiteRelativePath -Connection $TargetConn -Values @{Modified=$File.FieldValues.Modified; Created = $File.FieldValues.Created} | Out-null
   Write-host "Copied File from $($File.FieldValues.FileRef)" -f Green

Wrapping up

In conclusion, copying files from OneDrive to SharePoint Online is a simple process that can be done in a few steps, as explained above. By using the “Copy to” feature in OneDrive, you can quickly and easily move files and folders to SharePoint Online. This allows for better collaboration and sharing with your team while keeping your files organized. It’s important to note that you can also use the same process to copy files from SharePoint Online to OneDrive.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

3 thoughts on “How to Copy Files from OneDrive to SharePoint Online?

  • Is there a way to do this via PowerShell?

    • Sure! Post updated with the PowerShell script to copy files from OneDrive to SharePoint.

  • The best way to copy Files from OneDrive to SharePoint Online is by using tools like Sharegate or Gs Richcopy 360 .
    Although there are many tools ,I prefer the easy way to make my data safe


Leave a Reply

Your email address will not be published. Required fields are marked *