Using PowerShell to Bulk Upload Files to SharePoint

12 May, 2014 · less than a minute to read

Using PowerShell to Bulk Upload Files to SharePoint

While building a school's Learning Gateway I needed to bulk upload all their student images into a picture library so that the My Children web part could display them. Since there were several hundred of them I wrote a little PowerShell script to perform this.

$siteUrl = "http://sharepoint/schools/test" $listName = "Students Picture Library" [system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint") $site = New-Object Microsoft.SharePoint.SPSite($siteUrl) $web = $site.OpenWeb() $list = $web.Lists[$listName] $fileCollection = $list.RootFolder.Files $files = get-childItem -Exclude *.ps1 foreach ($file in $files) {    $stream = $file.OpenRead()     $uploaded = $fileCollection.Add($file.Name, $stream, $TRUE)     "Uploaded " + $file.Name    if ($stream) {$stream.Dispose()} } if ($web) {$web.Dispose()} if ($site) {$site.Dispose()}

In order to use this: 

  1. Save as as .ps1 file in the same folder as the files to upload.
  2. Change the site url and name of the list at the beginning of the script to your values
  3. Make sure that only the files to upload and the ps1 file is in the folder
  4. Open PowerShell using Run As Administrator
  5. Navigate to the folder
  6. Run the .ps1 file

The script will then iterate through all files in the current folder and upload them to the given list, overwriting them if they already exist.

Richard Willis headshot

Written by Richard Willis

Managing Director / Founder

Richard started SalamanderSoft in 2007 after a successful career as a software developer. Wanting to start his own company and with experience in integrating school systems he set out to build the best integration system for schools and to exceed customer expectations. He starting out on his own, doing all the coding, support and sales until finally the growing number of customers meant he needed to start growing the team. He is still heavily involved in coding the core Integration Suite product in addition to running the company and being the first point of contact for prospective customers.

Copyright © 2020 SalamanderSoft Limited