Recently, one of my clients asked me to upload some files from their local drive to a SharePoint Online document library. I tried PnP PowerShell, and that worked great. In this tutorial, I will explain how to upload files to a SharePoint document library using PnP PowerShell. We will cover uploading a single file as well as multiple files to a SharePoint library.
Here, I have created a document library in my SharePoint Online site, and I have a local folder with some files in it. We will upload these local files to the SharePoint library.


Upload a Single File to SharePoint Online using PnP PowerShell
Now, first, let me show you how to upload a single file to a SharePoint Online document library using PnP PowerShell.
Here is the complete PowerShell script.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Upload the file
Add-PnPFile -Path "C:\MyNewFolder\MyWordFile.docx" -Folder "HRDocuments"Once you execute the above PowerShell script, it will upload the file to the SharePoint document library. I took the screenshot below after I executed the script.

This is how easily you can upload a single file to a SharePoint library using PnP PowerShell.
While uploading documents, sometimes you might need to update column values, and for that, you can write the PnP PowerShell script like the below:
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Upload the file
Add-PnPFile -Path "C:\MyNewFolder\MyWordFile.docx" -Folder "HRDocuments"
Set-PnPListItem -List "HRDocuments" -Identity $file.ListItemAllFields.Id -Values @{"Column1"="Value1"; "Column2"="Value2"; "Column3"="Value3"}Read Download Files from SharePoint Document Library Using PnP PowerShell
Upload Multiple Files to SharePoint using PnP PowerShell
Now, let me show you how to upload multiple files to a SharePoint library using PnP PowerShell.
In this case, as I said before I have a few files inside my local folder.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
$folderPath = "C:\MyNewFolder"
$files = Get-ChildItem -Path $folderPath
foreach ($file in $files) {
Add-PnPFile -Path $file.FullName -Folder "HRDocuments"
}Once you execute the above script, you can see it will upload all the files from the local drive to the SharePoint library. Check the screenshot below:

Also, if you want to update column values while uploading documents to the SharePoint document library, you can write the below PnP PowerShell script.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
$folderPath = "C:\MyNewFolder"
$files = Get-ChildItem -Path $folderPath
foreach ($file in $files) {
Add-PnPFile -Path $file.FullName -Folder "HRDocuments"
Set-PnPListItem -List "HRDocuments" -Identity $uploadedFile.ListItemAllFields.Id -Values @{"Column1"="Value1"; "Column2"="Value2"; "Column3"="Value3"}
}Conclusion
In this tutorial, I have explained how to upload documents to a SharePoint document library using PnP PowerShell. I have explained how to upload a single document to SharePoint using PnP PowerShell. And also, I have explained about bulk upload files to SharePoint using PnP PowerShell.
You may also like the following tutorials:
- Check if a List Exists in SharePoint Site using PnP PowerShell
- Check if a Folder Exists in SharePoint Online using PnP PowerShell
- Copy Items from One List to Another in SharePoint Online Using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.