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 list of files pointing to a network file share. We wanted to import all files from a CSV file to SharePoint Online site. Here is the PowerShell script to bulk import files from a CSV:
#Parameters
$SiteURL = "https://crescent.SharePoint.com/sites/ostro"
$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)"
    $Counter++
}
The Add-PnpFile cmdlet automatically creates nested folder structure, if its not there in given SharePoint path already!

Here is my CSV File:
powershell to import files to sharepoint online from csv

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.