Use PowerShell to Find Available SharePoint List and Library Templates


While there are about 500 available cmdlets right OOTB in SharePoint 2010, I still find things from time to time that don’t have a cmdlet readily available. A great example is finding available List or Library templates.

I’m currently working on a project where I’m going to need to create a LOT of libraries of all different types. I could’ve done a lot of clicking, but who would want to do that?!

Instead, I used PowerShell and the SP Object Model to automate the retrieval of available list templates as well as the creation of lists based on said templates. This blog post will focus solely on getting the available templates. Note: Depending on which site and web features are activated, as well as which SKU you have – your templates will vary.

Here is the function:

function Get-SPListTemplates {
<#
.Synopsis
	Use Get-SPListTemplates to obtain available list and library templates.
.Description
	This advanced PowerShell function uses the SharePoint Object Model to retrieve available list and library templates in a SharePoint site specifified in the Web parameter.
.Example
	C:\PS>Get-SPListTemplates -Web http://intranet
	This example retrieves available list templates in the http://intranet site.
.Example
	C:\PS>Get-SPListTemplates -Web http://intranet -Library
	This example retrieves available library templates in the http://intranet site.
.Notes
	Use this advanced function to retrieve list and library templates.
.Link
	http://www.iccblogs.com/blogs/rdennis
 		http://twitter.com/SharePointRyan
.Parameter Web
	The URL of an SPWeb.
#>
	[CmdletBinding()]
	Param(
	[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
	[string]$Web,
	[Parameter(Mandatory=$false)]
	[switch]$Library
	)
Start-SPAssignment -Global
$SPWeb = Get-SPWeb -Identity $Web
if ($Library) {
	$Templates = $SPWeb.ListTemplates | Where-Object {$_.Name -match "Library"} | Format-List -Property Name
} 
else {
	$Templates = $SPWeb.ListTemplates | Where-Object {$_.Name -notmatch "Library"} | Format-List -Property Name
}
Write-Host "The following templates are available:"
$($Templates)
$SPWeb.Dispose()
Stop-SPAssignment -Global
}
Advertisement

5 thoughts on “Use PowerShell to Find Available SharePoint List and Library Templates

  1. brothergabriel

    Salve! I was looking at this, but it does not fetch custom lists nor libraries. I am trying to write a powershell script to create a new library from a library template that I used by exporting a library that I made.

    • Ryan Dennis

      I have not updated the script to handle custom lists and libraries, but here is the code to fetch a custom list template:
      $Site = Get-SPSite http://
      $Web = $Site.RootWeb
      $ListTemplate = “ListTemplateName”
      $listTemplates = $Site.GetCustomListTemplates($Web)
      $Template = $listTemplates | Where-Object {$_.InternalName -eq $ListTemplate}

      Hope this helps!
      Ryan

  2. brothergabriel

    You are very kind, Mr. Dennis. Now, I supply my site, and the ListTemplateName being the file name of my custom template, but it doesn’t return anything. I think I am missing something.

Leave a Reply

Please log in using one of these methods to post your comment:

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