Powershell Week – Day 1: Copy List Structure Using Template
June 18, 2012 Leave a comment
This week I’m starting a series of posts with several Powershell scripts I’ve been writing to help with some activities that might take a long time if you do it manually. I hope you enjoy the Powershell scripts as I do!
This first one is about creating a list or document library based on an existing one. The approach used is to save the existing library as a template and then creating the new one based on the template.
$site = get-spsite("http://www.yourwebapplication.com") $web = $site.Allwebs["your web site"] $list = $web.Lists["your library"] $list.SaveAsTemplate("TemplateName.stp", "TemplateName", "Template Name", $false) # the last parameter defines wheter you want the data to be saved in the template $listTemplates = $site.GetCustomListTemplates($web) $web.Lists.Add("New List URL", "New list Name", $listTemplates["TemplateName"])
If you want, you can also delete the template after the copy is created.