Upload files to SharePoint Library

A PowerShell with SharePoint tutorial

PowerShell iconSharePoint has several methods to upload files from Windows Explorer to a document library, but if you want to do it automatically, you should use a PowerShell script.

In such a scenario, you can put all files that should be uploaded in a specific folder and then they will be uploaded automatically to the SharePoint library of your choice.

In a later article, Peter Kalmström will explain how to schedule such tasks, but here he will just show how to upload all the files in a Windows Explorer folder to a SharePoint document library.

Peter uses the cmdlet Get-ChildItem to copy the items in the Windows Explorer folder to an array that contains all items in the folder. After that, he can add them to the SharePoint library with a forEach loop and the cmdlet Add-PnPFile.

$Files = Get-ChildItem "C:\Users\PeterKalmström\Documents\ToImport"
foreach($File in $Files){
    #$File = $Files[0]
    Add-PnPFile -Folder "Shared Documents" -Path $File.FullName

PowerShell with SharePoint from Scratch cover We will expand this script in the next article, so that copied files are move to a subfolder and not included in the next run. After that we will make it automatic.

You will find more detailed explanations in the book.

back icon next icon
Products Buy FAQ Services Tips Books Contact About Us Tools

Security and integrity

Copyright  Kalmstrom Enterprises AB  All rights reserved