Saturday, October 9, 2021

Powershell : Resotre a site collection from backup

Leave a Comment

How to restore SharePoint 2013 / 2016/ 2019 site collection from site backup


Scenario

Recently for a vendor based revamped project, vendor provided us site backup instead to restore on our Dev / QA environment. To quickly restore a site collection with SharePoint 2013 / 2016 / 2019 environment from site backup I used following power shell command.


Restore-SPSite -Identity "http://SharePoint/site/"-Path C:\Vendor_SiteBackup\v2.0\SomeBackupname.bak -Force


Here -force optional parameter will be used to overwrite existing site collection where we want to restore our site backup

Read More

Thursday, October 7, 2021

Powershell: save list and library as template in sharepoint 2013 / 2016 / 2019

Leave a Comment

  

Business Scenario

This is quite usual scenario where developers or site admin have to move newly create list or libraries from Dev environment to Staging / Production. This blog will show options for doing it manually as well as through Powershell. This is series of blog where:

  1. Save list / library with or without data as list template through powershell.
  2. Create new list / library using template through powershell

 

 Manual way of saving list as template

After creating and verifying business usability of custom list or library with all custom column etc, if we want to save this list as list template to be used on same farm / environment or other other farms to recreate same list with similar schema or data, we need to follow these steps:

  • Open your custom sharepoint list and go to list settings.
  • From settings under permission and management section, click save list as template
  • Provide template name and file name and choose option if need to save list data along with schema.
  • Once list template save it prompts for operation successful page message along with link to list template gallery

 

 

 Powershell to the rescue

Lets say we need to save multiple list as list templates, so instead of doing it manually we can customize following script:

#Import SharePoint Snapin
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Configuration parameters
$WebURL="http://sharepoint site"
$ListName="List name"
$TemplateName="Template Name"
$TemplateFileName="Template File Name"
$TemplateDescription="Some description"
$SaveData = $false
 
#Get the Web and List objects
$Web = Get-SPWeb $WebURL
$List = $Web.Lists[$ListName]
 
#Save List as Template
$List.SaveAsTemplate($TemplateFileName, $TemplateName, $TemplateDescription, $SaveData)
Write-Host "List Saved as Template!




and saved list is available in list template gallery

Read More