Saving a list as a list template & creating lists from custom template using PowerShell

Posted on Updated on


  • To save list as a template use following code

$site = get-spsite("http://testsite")

$web = $site.RootWeb

$list = $web.Lists["Announcements"]

SharePoint $list.SaveAsTemplate() PowerShell Command use following parameters.

$list.SaveAsTemplate(“Template Name”,”Template Title”,”Template Description”,1)

In the forth parameter of SaveAsTemplate(), if you want to save the specified site as template along with data use 1, otherwise use 0.

Eg:- $list.SaveAsTemplate("TestListTemplate.stp", "TestListTemplate", "Test List Template", $false)

 

  • Creating a new list from the template created.

$listTemplates = $site.GetCustomListTemplates($web)

$web.Lists.Add("TestList", "Test List", $listTemplates["TestListTemplate"])

Advertisements

2 thoughts on “Saving a list as a list template & creating lists from custom template using PowerShell

    Kai said:
    February 18, 2014 at 6:28 PM

    Hi Praneeth,

    first of all – thanks for your post.
    But i think “$Web.SaveAsTemplate(“Template Name”,”Template Title”,”Template Description”,1)” is the wrong commant to save the list as a template. I think you mean “$list.SaveAsTemplate”

      hpksanje responded:
      April 9, 2014 at 1:12 AM

      Hi Kai,

      yes it $list not $Web.thanks for showing my mistake. Really appreciate it.

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 )

Google photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s