How to Upload bulk documents to SharePoint 2016 document library using PowerShell

Here in this post, we will discuss how we can upload bulk documents to SharePoint 2016 document library using PowerShell. The same PowerShell script also works fine in SharePoint 2013 also.

Here we will upload documents to the default “Documents” document library which is there in SharePoint 2016. I have a folder in my local drive which contains few files.

We will upload those files to the SharePoint 2016 document library by using PowerShell.

Also read: Upload large files to SharePoint online document library using PowerShell csom

Below is the PowerShell script which you can run in PowerShell ISE.

function UploadDocuments($destination, $File)
{
$securePassword=ConvertTo-SecureString "Qwe@12345" -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential("MYSP\Administrator",$securePassword)
$webclient=New-Object System.Net.WebClient
$webclient.Credentials=$credentials
$webclient.UploadFile($destination+"/"+$File.Name,"PUT",$File.FullName)
}
$destination="http://mypc:29024/sites/HydTraining/Shared%20Documents/"
$fileDirectory="E:\Users\Administrator\Desktop\FilesToUpload\*.*"
foreach($fileName in Get-ChildItem $fileDirectory)
{
UploadDocuments -destination $destination -File $fileName
Write-Output "Upload file " $fileName
}
Write-Host "Documents uploaded successfully"

Once you run the script, you will see files will be uploaded to document library like below:

Upload bulk documents to SharePoint 2016 document library using PowerShell
Upload bulk documents to SharePoint 2016 document library using PowerShell

Read some PowerShell tutorials:

I hope this article will help you to upload documents to SharePoint 2016/2013 document library.

>