SharePoint Online: Import Files from a CSV using PowerShell

Requirement: Upload files from a CSV to SharePoint Online.

SharePoint Online: How to Import Files from a CSV using PowerShell?

We have got a CSV file with a list of files pointing to a network file share. We wanted to import all files from a CSV file to the SharePoint Online site. Here is the PowerShell script to bulk import files from a CSV:

$SiteURL = ""
$CSVFile = "C:\Users\Salaudeen\Desktop\Intralink-Mapping-v2.csv"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin

#Get the data from CSV file
$CSVData = Import-CSV $CSVFile
$Counter =1

#Loop through each Row in the CSV file and upload file to SharePoint
ForEach($Row in $CSVData)
    $File = Add-PnPFile -Path $Row.SourceFilePath -Folder $Row.FolderSiteRelativeURL -NewFileName $Row.FileName
    Write-Host "Uploaded File $($Row.FileName) - $Counter of $($CSVData.Count)"

The Add-PnpFile cmdlet automatically creates a nested folder structure, if it’s not there in the given SharePoint path already!

Here is my CSV File:

powershell to import files to sharepoint online from csv

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

Leave a Reply