Create copy of list using PowerShell

Use below script to save list to be copied as template and then create copy of list from the newly created list template.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$webURL = "http://contoso.com/TeamSite"
$listName = "MyList"
$newListName = "Archived $($listName)"

# Use 0 below if you want to copy only list structure, 1 if you want to copy list data along with structure
$saveListDataWithTemplate = 0 

$web = Get-SPWeb $webURL
$site = $web.Site
$list = $web.lists | where {$_.title -eq $listName}
$list.SaveAsTemplate("$($listName)Template","$($listName) Template","$($listName) Template",$saveListDataWithTemplate) #stpfilename, title, description, bSaveListDataWithTemplate

$listTemplates = $site.GetCustomListTemplates($web)
$web.Lists.Add($newListName, "$($listName) list",$listTemplates["$($listName) Template"])
Write-Host "$($newListName) List created."
$web.Dispose()

Please note that Posts list is unique in Blog site and hence we can not use above script for creating copy of Posts list in blog site. You get below error when you try to use this script for Posts list in blog site in SharePoint 2010:

"There can only be one instance of this list type in a web.
An instance already exists."

Sponsored Links

Published by Amol

Amol Awasare aka 'Sam' is highly passionate SharePoint Consultant who has extensively worked on various SharePoint editions starting with MOSS 2007, SP 2010, SP 2013, SP Online. Amol has started this blog to share his knowledge and connect with like minded people to explore SharePoint in all aspects.

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Create your website with WordPress.com
Get started
%d bloggers like this: