Create SharePoint 2013 List using out of box or custom template using PowerShell

InfoPath alternatives for form designing SharePoint

Recently We had some requirement to create list in 30 sites and subsites. We created the list and saved the list as template. Now creating same list in 30 sites and subsites is big pain.

So thought of writing PowerShell script which will create the list using out of the box template or custom list template.

Also check out some of my post on:
– Delete SharePoint 2013 List and Library using PowerShell

– Generate userprofile information PowerShell Script SharePoint 2013

– Create Page Programmatically CSOM PowerShell script SharePoint 2013

We need to create CSV file with below columns as input variables.
SiteURL
TemplateName
ListName
CustomTemplate – If its custom template we have to pass parameter as Yes or if you are using OOTB template pass the parameter value as No.

So the CSV will look like below image.

Create SharePoint 2013 List using out of box or custom template using PowerShell
Create SharePoint 2013 List using out of box or custom template using PowerShell

PowerShell Script-

$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$path = $(“$dp0\CreateListsFromTemplates.csv”)

$csv = Import-csv -path $path

foreach($line in $csv)
{
$strWebURL = $line.SiteURL
$customListTemplate = $line.CustomTemplate
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}

[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”) | Out-null

$web = Get-SPWeb $strWebURL
$site = $web.Site

$rootweb = $site.OpenWeb()
if($customListTemplate.ToLower() -eq “no”)
{
write-host “List Template: ” $line.TemplateName
$web.Lists.Add($line.ListName, “”, $line.TemplateName)
Write-Host $line.ListName ” list created Successfully…..”
}
else
{
$listTemplates = $site.GetCustomListTemplates($rootweb)
$web.Lists.Add($line.ListName, “”, $listTemplates[$line.TemplateName])
Write-Host $line.ListName ” list created Successfully…..”
}
$web.Dispose()
$rootweb.Dispose()
$site.Dispose()
}

Thanks,
Sambita

Similar SharePoint 2013 Tutorials


About Sambita Rath

I have 9 years of exprience into SharePoint implementation, architecture, Administrator, development and Training.Designing Information Architecture in SharePoint 2007, 2010,2013 and Office 365.

View all posts by Sambita Rath →

Leave a Reply