PowerShell script to Upload multiple Custom List template and create custom list instances

I this article I am going to present you to create multiple SharePoint Custom list instances using PowerShell.It is very helpful when we are working on migrating SharePoint environment.

In below example list name is same as the template which we are uploading to template gallery.

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

# Custom template path
$Path = "C:\CustomTemplate"

# Your site url
$oSite = Get-SPSite("htpp://localhost/")

# Get the root web
$oWeb = $oSite.RootWeb

# Get the list template gallery
$spLTG = $oWeb.GetFolder("List Template Gallery")

# Get the list template gallery Collection
$spcollection = $spLTG.files

# loop all stp files and upload/create custom list
Get-ChildItem $Path -Filter "*.STP" |
ForEach-Object {
$Templatefile = get-item $_.FullName
$catlogs="_catalogs/lt/" + $_.Name
$lstDesc="Description :" + $_.BaseName
$spcollection.Add($catlogs, $Templatefile.OpenRead(), $true)
$CustomlistTemplates = $oSite.GetCustomListTemplates($oWeb)
$oWeb.Lists.Add($_.BaseName, $lstDesc, $CustomlistTemplates[$_.BaseName])
Write-Host $_.BaseName+" List has been created" -foregroundcolor green
}

$oWeb.Dispose()
$oSite.Dispose()

2 thoughts on “PowerShell script to Upload multiple Custom List template and create custom list instances

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s