How to Upload bulk documents to SharePoint 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.

Upload bulk documents to SharePoint document library

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

Multiple connections to a server or shared resource by the same user rename computer

Recently while working with PowerShell to copy files from local drive to SharePoint document library I got the below error: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

The full error message looks like below:

net : System error 1219 has occurred.
At C:\Users\Bijaya.Sahoo\Desktop\LargeFileUpdated.ps1:181 char:1
+ net use $fileDirectory /USER:$username $password
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (System error 1219 has occurred.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

Multiple connections to a server or shared resource by the same user
Multiple connections to a server or shared resource by the same user

multiple connections to a server or shared resource by the same user rename computer

The fix the error multiple connections to a server or shared resource by the same user rename computer, run the below command:

net use * /delete

This is how to fix error multiple connections to a server or shared resource by the same user rename computer.

Read some PowerShell tutorials:

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

>