I would like to modify the Powershell Script found at the following site:


I would like to upload all Folders, subfolders and files it finds at a specific source on local drive to the Document Library.

And specifically into a folder names: Resources

Local path: C:\Main\Resources

SharePoint online library (for example) :


Within the Documents folder, there is a folder called Resources

I would like to upload all Files and Folders from C:\Main\Resources to that Resources folder on the SharePoint Online site.

  • Unfortunately the link in the question is now invalid, so it's very hard to answer this question today. Some of the answers, however, are still useful.
    – Kristian
    Feb 5, 2021 at 14:23

2 Answers 2


I'm recommending to you, use SharePoint Migration tool from Microsoft. You can simply and effectively migrate FileSystem, SharePoint 2013 to SharePoint Online.


For PowerShell solution, you could check the script shared by Romeo Donca.

This script can be useful to update a specific field on a library located on a Sharepoint Online tenant
You need to know 5 mandatory parameters: 
    - url_sharepoint         : the URL for root site collection
    - library                : the name of the destination library
    - url_site               : the relative path of the site

This script can be used as it is or can be changed based on your needs. For more details please feel free to contact me
Romeo Donca, February 2017
[email protected]

[Parameter(Mandatory=$true,HelpMessage="The root site collection URL")][string]$url_sharepoint,
[Parameter(Mandatory=$true,HelpMessage="The relative path for the site site URL ___ /sites/subsite")][string]$url_site,
[Parameter(Mandatory=$true,HelpMessage="The name for the library")][string]$library
$t1  = get-date
$source_folder = ((new-object -com Shell.Application).BrowseForFolder(0, "Select the source folder", 0, "")).Self.Path
$url = $url_sharepoint+$Url_site

Add-Type -Path "your_path\Microsoft.SharePoint.Client.dll" 
Add-Type -Path "your_path\Microsoft.SharePoint.Client.Runtime.dll" 
Import-Module MSOnline
$global:cred1 = Get-Credential
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred1.username, $cred1.Password)  
$clientContext.Credentials = $cred
$web = $clientContext.Web
$mylist = $web.GetList($url+"/"+$library)
###################### get folders existing  in the SOURCE
$directories= @()
foreach ($file in (Get-ChildItem  -Recurse -Path $source_folder -Attributes Directory))
    $directories +=($file.FullName.ToLower()).replace($source_folder.ToLower()+'\','')
foreach ($directory in $directories)
    $myfolder = $mylist.RootFolder
    $myfolder = $myfolder.Folders.Add($directory.split('\')[0])
    for ($i = 1; $i -le ($directory.split('\').Count-1) ; $i++)
        $myfolder = $myfolder.folders.Add(($directory.split('\'))[$i])
$t1  = get-date
$count = ((Get-ChildItem -File  -Recurse -Path $source_folder) | Measure-Object -Property FullName ).Count
foreach ($file in (Get-ChildItem -File  -Recurse -Path $source_folder))
    $t01  = get-date
    $url_dest = $url_sharepoint+$Url_site+'/'+$library+(($file.FullName.ToLower()).Replace($source_folder.ToLower(),'')).Replace('\','/')
    $FileStream = New-Object IO.FileStream($File.FullName,[System.IO.FileMode]::Open)
    $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
    $FileCreationInfo.Overwrite = $true
    $FileCreationInfo.ContentStream = $FileStream
    $FileCreationInfo.URL = $url_dest
    $Upload = $mylist.RootFolder.Files.Add($FileCreationInfo)
    $listItem = $upload.ListItemAllFields
    Write-Host " Uploading file $i/$count $url_dest"
    $t02  = get-date
    $speed ="{0:n2}" -f ($file.Length/($t02-$t01).TotalSeconds/1mb)
    Write-Host "...................upload speed was " $speed " MB/sec"
$size = "{0:n2}" -f (gci -path $source_folder -recurse | measure-object -property length -sum).sum
$speed ="{0:n2}" -f ($size/($t2-$t1).TotalSeconds/1mb)
Write-Host "Medium upload speed was " $speed " MB/sec"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.