Create list and libraries from 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
###### 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
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
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.