Create list template sharepoint 2013 powershell

Introduction

In SharePoint, the list templates provide re-usability of columns without recreating it on every single site. For e.g. I have created a custom list which name is Project, in a SharePoint site collection with all relevant columns, Now I want this list structure in other site collections, without recreating the list on every single site.

Steps to save a list or library as a template

Go to a SharePoint list, then navigate to list settings present under the list tab on the ribbon and then click on List Settings.

Click on Save list as Template under Permissions and Management group.

Provide template Filename and Template name. If you want to include the content, then select the check box, Click Ok

Click OK on the success page.

How to download the list template

Go to site setting, Click on List Templates under web Designers and Gallery.

Click on Upload Document on the Files tab, then browse your file i.e-Demo.stop

You can also save the list template to your site by using PowerShell script,

  1. try{
  2. Add-Type-Path"..\Microsoft.SharePoint.Client.dll"
  3. Add-Type-Path"..\Microsoft.SharePoint.Client.Runtime.dll"
  4. $SiteUrl=Read-Host"EntertheSiteUrl"
  5. $UserName=Read-Host"Entertheusername"
  6. $Password=Read-Host-AsSecureStringPassword
  7. $ctx=New-ObjectMicrosoft.SharePoint.Client.ClientContext[$siteUrl]
  8. $Credentials=New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials[$UserName,$Password]
  9. $ctx.Credentials=$credentials
  10. $Web=$Ctx.Web
  11. $site=$Ctx.Site
  12. $ctx.Load[$web]
  13. $ctx.Load[$site]
  14. $ctx.ExecuteQuery[]
  15. $ListName=Read-Host"EntertheListName"
  16. $list=$Ctx.Web.lists.GetByTitle[$ListName]
  17. $FileName=Read-Host"EntertheFileName"
  18. $TemplateName=Read-Host"EntertheTemplateName"
  19. $list.SaveAsTemplate[$FileName,$TemplateName,"listtemplatedescription",$true]
  20. $ctx.ExecuteQuery[]
  21. Write-Host-ForegroundColorGreen"SuccessfullysavethelistTemplate."
  22. sleep10
  23. }catch{
  24. Write-Host-ForegroundColorRed'Error',':'
  25. $Error[0].ToString[];
  26. sleep10
  27. }

Follow the below screenshot and enter the values into the parameters accordingly. Then you can get a successful message.

How to upload list template to another site

Go to site setting, Click on List Templates under web Designers and Gallery.

Click on Upload Document in the Files tab, Then browse your file i.e-Demo.stp

Go to Site contents, Click on New then select App.

Now your list added to the site successfully.

You can also add the list template to your site by using PowerShell script,

  1. try{
  2. Add-Type-Path"..\Microsoft.SharePoint.Client.dll"
  3. Add-Type-Path"..\Microsoft.SharePoint.Client.Runtime.dll"
  4. $SiteUrl=Read-Host"EntertheSiteUrl"
  5. $UserName=Read-Host"Entertheusername"
  6. $Password=Read-Host-AsSecureStringPassword
  7. $ctx=New-ObjectMicrosoft.SharePoint.Client.ClientContext[$siteUrl]
  8. $Credentials=New-ObjectMicrosoft.SharePoint.Client.SharePointOnlineCredentials[$UserName,$Password]
  9. $ctx.Credentials=$credentials
  10. $Web=$ctx.Web
  11. $site=$ctx.Site
  12. $ctx.Load[$web]
  13. $ctx.Load[$site]
  14. $ctx.ExecuteQuery[]
  15. $Template=$site.GetCustomListTemplates[$Web]
  16. $Lists=$ctx.Web.Lists
  17. $ctx.Load[$Lists]
  18. $ctx.Load[$Template]
  19. $ctx.ExecuteQuery[]
  20. $TemplateName=Read-Host"EntertheTemplateName"
  21. $ListName=Read-Host"EntertheListName"
  22. $ListTemplate=$Template|where{
  23. $_.Name-eq$TemplateName
  24. }
  25. $List=$Lists|where{
  26. $_.Title-eq$ListName
  27. }
  28. If[$List-eq$Null]{
  29. $ListCreation=New-ObjectMicrosoft.SharePoint.Client.ListCreationInformation
  30. $ListCreation.Title=$ListName
  31. $ListCreation.ListTemplate=$ListTemplate
  32. $List=$Lists.Add[$ListCreation]
  33. $ctx.ExecuteQuery[]
  34. }
  35. Write-Host-ForegroundColorGreen"SuccessfullyAddthelist."
  36. sleep10
  37. }catch{
  38. Write-Host-ForegroundColorRed'Error',':'
  39. $Error[0].ToString[];
  40. sleep10
  41. }

Follow the below screenshot and enter the values for the parameters accordingly. Then you can get a successful message.

Video liên quan

Chủ Đề