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.
- $SiteURL = "https://xyzeur.sharepoint.com/sites/S022-013-IS/TestMigration"
- $FilesPath = "C:\Users\123594\Dummy Files"
- $SiteRelativePath = "/DemoLibrary/"
- #Connect to PNP Online
- Connect-PnPOnline -Url $SiteURL -UseWebLogin
- #Get All Files from a Local Folder
- $Files = Get-ChildItem -Path $FilesPath -Force -Recurse
- #Upload All files from the directory
- ForEach ($File in $Files)
- {
- Write-host "Uploading $($File.Directory)\$($File.Name)"
- #upload a file to sharepoint online using powershell - Upload File and Set Metadata
- Add-PnPFile -Path "$($File.Directory)\$($File.Name)" -Folder $SiteRelativePath -Values @{"Title" = $($File.Name)}
- }
Note
It can only upload files but not folders from the given folder path, as explained in the above script.
Here is the output, as shown below.
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!!