Data / Provision

Add multiple lists or libraries using csv file

This script sample shows how to bulk create lists or libraries using CSV file

Summary

This script sample will bulk create lists or libraries using CSV file

Implementation

  • Open Windows PowerShell ISE
  • Edit Script and add required parameters for Site URL and path to CSV file
  • Press run
powershell

###### Declare and Initialize Variables ######  

#Destination site collection url
$url="https://<tenant>.sharepoint.com/sites/yoursite"

#Path to CSV file
$csvFilePath = "ListsAndLibraries.csv"


# log file will be saved in same directory script was started from
$saveDir = (Resolve-path ".\")  
$currentTime= $(get-date).ToString("yyyyMMddHHmmss")  
$logFilePath=".\log-"+$currentTime+".log"  

## Start the Transcript  
Start-Transcript -Path $logFilePath 



## Connect to SharePoint Online site  
Connect-PnPOnline -Url $Url -Interactive

## Import CSV file
$data = Import-Csv -Path $csvFilePath -Delimiter ";"

## Create list or library
$data | Foreach-Object{
   
   New-PnPList -Title $_.Title -Url $_.Url -Template $_.Template -OnQuickLaunch -EnableContentTypes 
   
}  
 
## Disconnect the context  
Disconnect-PnPOnline  
 
## Stop Transcript  
Stop-Transcript  
  

Contributors

Author(s)
Valeras Narbutas

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Tool documentation & references

Keep exploring