Friday, September 12, 2014

How to Create a Subsite in SharePoint with PowerShell

Although creating subsites can be easily managed from SharePoint Web UI, We can also use PowerShell cmdlet New-SPWeb to create subsites programmatically in SharePoint. This is extremely helpful when you have to create a bunch of subsites under any SharePoint 2010/2013 site collection or when you have to create subsites in bulk Or when the SharePoint UI
doesn't provide an option to create site with "Blank" template!. Here is how to create SharePoint subsite using PowerShell:

On successful creation of subsite, New-SPWeb cmdlet should return URL of the subsite as in the above screen.

If there is no value for Template parameter is given, SharePoint prompts to select a web template when you open the subsite for the first time.

Well, while the above script simply provides an easier way to create subsite using PowerShell, lets explore other options such as permissions, navigation, etc in creating subsites in SharePoint 2013 using PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Variables for site creation
$SiteTitle = "Purchase Portal"
#Site description
$SiteDescription ="Portal for Purchase Department Portal"
#URL for you new subsite
$SiteUrl = "http://demo.pccs.com/travel/"
#Templte to be assigned to the subsite
$WebTemplate = "STS#0" #Team Site template
# AddToTopNav - Adds the new site within the top navigation of the site collection
# UseParentTopNav - Replicates the top navigation of the site collection into the new subsite
# UniquePermissions - Instructs not to inherit permissions from the site collection
#create subsite using powershell sharepoint 2010/SharePoint 2013
New-SPWeb -Name $SiteTitle -Description $SiteDescription -Url $SiteUrl -Template $WebTemplate –AddToTopNav –UniquePermissions –UseParentTopNav