Thursday, January 8, 2015

Save site as template -SharePoint 2013

A small script to save as template for SharePoint 2013 sites. This script also handle publishing feature enabled sites. I wrote this script to save some time. Instead of click few places , just run the script. :)


param(
    [string] $url = $(throw "No URL! Usage: Save-SP13Template.ps1 [webURL] [FileName]"),
[string] $templateName = $(throw "No Template Name! Usage: Save-SP13Template.ps1 [webURL] [TemplateName]")
)

#-------------------------------------------------------------


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
function Save-SiteTemplate {

$Web=Get-SPWeb $url
$Web.SaveSiteAsTemplateEnabled = $true
$Web.Update()
$fileName =$templateName +".wsp"
$Web.SaveAsTemplate($fileName,$templateName,"Template Description",1)
}

Save-SiteTemplate

No comments:

Post a Comment