Simple Uploading PowerShell Script On A SP Online Library

Introduction 

 
Hi guys, let's explore the smoothest and easiest way to upload all the files present in your local desktop path to a SharePoint online library.
We need to install a few NuGet package installations to avoid unnecessary errors by running the below scripts.
 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Install-PackageProvider -Name NuGet
Install-Module -Name SharePointPnPPowerShellOnline
 
Here is uploading the PnP script to run. You need to do the configurations accordingly.
  1. $SiteURL = "https://xyzeur.sharepoint.com/sites/S022-013-IS/TestMigration"  
  2. $FilesPath = "C:\Users\123594\Dummy Files"  
  3. $SiteRelativePath = "/DemoLibrary/"  
  4. #Connect to PNP Online  
  5. Connect-PnPOnline -Url $SiteURL -UseWebLogin  
  6. #Get All Files from a Local Folder  
  7. $Files = Get-ChildItem -Path $FilesPath -Force -Recurse  
  8. #Upload All files from the directory  
  9. ForEach ($File in $Files)  
  10. {  
  11.    Write-host "Uploading $($File.Directory)\$($File.Name)"  
  12.    #upload a file to sharepoint online using powershell - Upload File and Set Metadata  
  13.    Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder $SiteRelativePath -Values @{"Title" = $($File.Name)}  
  14. }  
Note
It can only upload files but not folders from the given folder path, as explained in the above script.
 
Simple Uploading PowerShell Script On A SP Online Library 
Here is the output, as shown below.
 
Simple Uploading PowerShell Script On A SP Online Library
 Simple Uploading PowerShell Script On A SP Online Library
 
Upload Speed for 1k Dummy Files: 1.86 GB/19 Mins = 0.09 GB/Min
 
I would also suggest go for the direct drag and drop modern upload option on any Document Library, which completes faster + includes Folders/SubFolders too!!
 
Note
The above speeds can vary wrt to the LAN/Wi-Fi Connection too!!
 
We've come to know the above PnP script for our business requirements. It can be programmed to be automated by calling it into another program or via Azure Web Jobs/Azure Functions etc.
 
Cheers!!