Before reading this article, please go through the following article:
- Introduction
- Document Objective
- Audience
- Creating Site Collection and then sub site within same site collection.
- Procedure
- Procedure
- Creating Sub Site under already created Site collection.
- Procedure
- Procedure
- PowerShell Script
Introduction
- Document Objective
The purpose of this document is to provide instructions on using this PowerShell script to create site collections and sites in SharePoint using different web templates. - Audience
This document is targeted to developers and architects responsible for creating site collections and sites using multiple combinations with different web templates. Please note that root site collection must be present with web application URL. The code can be modified and extended as per requirements.
Creating Site Collection and then sub site within same site collection
Procedure
- Go to Start > Open SharePoint 2013 Management Shell.
- Run as administrator.

- Run the script.

- Enter Web application url. Press Enter.

- It will validate the web application url. If root site collection is present at web application url, it will ask if user wants to create site collection or sub site.

- Enter 1. It will ask the site collection details. Enter Site Title, Site description and Site Url (must be a valid URL) URL is pre-populated in ‘e.g’ part. User can use this URL.

- After entering all details, it will ask for web template category choice.
Enter 1. Then, it will ask for web template for this particular web template category.
Enter 1 for Team Site.
- Enter Primary administrator and Secondary Administrator (optional) details.Press Enter.

- Site Provisioning process will take place.

- After Site Collection got provisioned, it will ask if user wants sub site to be created under newly created site collection.

- Enter “y”. It will ask for Sub Site details. Enter these details.

- Site Provisioning process will take place.

- After successfully provisioning the site, it will ask if another sub site to be created under same site collection.

- Enter “y” if user wants another sub site to be created under same site collection. Otherwise enter “n”.

- Then it will ask if another site collection under same web application to be created.
Enter “y” if user wants another site collection to be created under same web application. Otherwise enter “n”.
- Then it will ask if another Site collection or sub site to be created. Enter “y”.

- User can follow steps 5 to 13 to create multiple site collections and sub sites with different web templates.
Creating Sub Site under already created Site collection
Procedure
- Go to Start > Open SharePoint 2013 Management Shell.
- Run as administrator.
- Run the script.
- Enter Web application url. Press Enter.
- It will validate the web application url. If root site collection is present at web application url, it will ask if user wants to create site collection or sub site.
- Enter 2.

- Enter the site collection url under which the sub site is to be created.
It will validate the entered site collection URL. - Enter the sub site details. Select ‘Records Center’ web template from ‘Enterprise Site template’ category.

- As Records center needs Publishing feature to be activated on parent site collection. So first Publishing feature is activated at parent site collection and then sub site will be provisioned.

- After provisioning sub site successfully, it will ask if another sub site to be created within same site collection.
- Enter “y” if user wants another sub site to be created under same site collection. Otherwise enter “n”.
- Then it will ask if another Site collection or sub site to be created. Enter “y” if user wants another site collection or sub site to be created. Otherwise, enter “n”.

PowerShell Script
- if ((Get - PSSnapin | Where
- {
- $_.Name - eq "Microsoft.SharePoint.PowerShell"
- }) - eq $null)
- {
- Add - PSSnapinMicrosoft.SharePoint.PowerShell;
- }
- ##Load SharePoint DLL
- [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
- functionGetUserInput([string] $sourceWebURL)
- {
- try
- {
- write - host "Validating if the entered site exists...$sourceWebURL"
- $site = Get - SPSite $sourceWebURL - ErrorActionSilentlyContinue
- if ($site - ne $null)
- {
- write - host "Successfully Validated the following Site Collection: $sourceWebURL" - ForegroundColor Green
- return $true;
- }
- else
- {
- return $false;
- }
- }
- catch [System.Exception]
- {
- DisplayErrorMsg($_.Exception.ToString())
- }
- }
- functionCreateSiteCollection([string] $sourceWebURL)
- {
- try
- {
- $spSourceWeb = Get - SPWeb $sourceWebURL
- $spSite = Get - SPSite($sourceWebURL)
- $spWeb = $spSite.OpenWeb()
- $createSiteColl = "Y"
- while ($createSiteColl - eq "Y" - or $createSiteColl - eq "y")
- {
- $SiteDescription = $null
- write - host "Please enter the Site Title : " - ForegroundColor Yellow
- $SiteTitle = read - host
- write - host "Please enter the Site Description : " - ForegroundColor Yellow
- $SiteDescription = read - host
- $spaceremovedsitetitle = $SiteTitle - replace " ", ""
- write - host "Please enter the Site Collection URL : (e.g. $sourceWebURL/sites/$spaceremovedsitetitle)" - ForegroundColor Yellow
- $sourceSiteCollURL = $sourceWebURL += "/sites/"
- $SiteUrltemp = read - host $sourceSiteCollURL
- $SiteUrltemp = $SiteUrltemp - replace " ", ""
- $SiteUrl = $sourceSiteCollURL += $SiteUrltemp
- Write - Host Site Collection URL is: $SiteUrl - ForegroundColor Green
- $SpaceRemovedURL = $SiteUrl.trimend(" ")
- $SiteUrl = $SpaceRemovedURL
- $lastChar = $SiteUrl.Substring($SiteUrl.Length - 1, 1);
- if ($lastChar - eq "/")
- {
- $SiteUrl = $SiteUrl.Substring(0, $SiteUrl.Length - 1);
- }
- else
- {
- $SiteUrl = $SiteUrl;
- }
- $invalid = $false
- write - host "Please select the category for Site Template :" - ForegroundColor Cyan
- Write - Host "1 :Collboration Site Templates" - ForegroundColor Yellow
- Write - Host "2 : Enterprise Site Templates" - ForegroundColor Yellow
- Write - Host "3 : Publishing Site Templates" - ForegroundColor Yellow
- $category = Read - Host
- if ($category - eq 1)
- {
- write - host "Please select the Site Template :" - ForegroundColor Cyan
- Write - Host "1: Team Site" - ForegroundColor Yellow
- Write - Host "2: Blog" - ForegroundColor Yellow
- Write - Host "3: Developer Site" - ForegroundColor Yellow
- Write - Host "4: Project Site" - ForegroundColor Yellow
- Write - Host "5: Community Site" - ForegroundColor Yellow
- }
- elseif($category - eq 2)
- {
- write - host "Please select the Site Template :" - ForegroundColor Cyan
- Write - Host "1: Document Center" - ForegroundColor Yellow
- Write - Host "2: eDiscovery Center" - ForegroundColor Yellow
- Write - Host "3: Records Center" - ForegroundColor Yellow
- Write - Host "4: Business Intelligence Center" - ForegroundColor Yellow
- Write - Host "5: Enterprise Search Center" - ForegroundColor Yellow
- Write - Host "6: My Site Host" - ForegroundColor Yellow
- Write - Host "7: Community Portal" - ForegroundColor Yellow
- Write - Host "8: Basic Search Center" - ForegroundColor Yellow
- Write - Host "9: Visio Process Repository" - ForegroundColor Yellow
- }
- elseif($category - eq 3)
- {
- write - host "Please select the Site Template :" - ForegroundColor Cyan
- Write - Host "1: Publishing Portal" - ForegroundColor Yellow
- Write - Host "2: Enterprise Wiki " - ForegroundColor Yellow
- Write - Host "3: Product Catalog" - ForegroundColor Yellow
- }
- else
- {
- write - host "Please select valid Site template Category. Try again." - ForegroundColor Red
- $invalid = $true
- }
- if ($invalid - ne $true)
- {
- $templateType = read - host
- $primaryadmin = $null
- $secondaryAdmin = $null
- Write - Host "Please enter Primary Administrator(domainname\loginnamee.gcorp\administrator)" - ForegroundColor Yellow
- $userValue = read - host[Microsoft.SharePoint.SPUser] $primaryadmin = $spWeb.EnsureUser($userValue)
- Write - Host "Enter Secondary Administrator <Y/N>?" - ForegroundColor Yellow
- $IsSecondaryAdmin = read - host
- if ($IsSecondaryAdmin - eq "Y" - or $IsSecondaryAdmin - eq "y")
- {
- Write - Host "Please enter Secondary Administrator(domainname\loginnamee.gcorp\administrator)" - ForegroundColor Yellow
- $userSecondaryValue = read - host[Microsoft.SharePoint.SPUser] $secondaryAdmin = $spWeb.EnsureUser($userSecondaryValue)
- }
- if ($category - eq 1 - and $templateType - eq 1)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "STS#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "STS#0" - Language 1033
- }
- }
- elseif($category - eq 1 - and $templateType - eq 2)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "BLOG#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "BLOG#0" - Language 1033
- }
- }
- elseif($category - eq 1 - and $templateType - eq 3)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "DEV#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "DEV#0" - Language 1033
- }
- }
- elseif($category - eq 1 - and $templateType - eq 4)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "PROJECTSITE#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "PROJECTSITE#0" - Language 1033
- }
- }
- elseif($category - eq 1 - and $templateType - eq 5)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "COMMUNITY#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "COMMUNITY#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 1)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "BDR#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "BDR#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 2)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "EDISC#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "EDISC#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 3)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "OFFILE#1" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "OFFILE#1" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 4)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "BICenterSite#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "BICenterSite#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 5)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "SRCHCEN#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "SRCHCEN#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 6)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "SPSMSITEHOST#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "SPSMSITEHOST#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 7)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "COMMUNITYPORTAL#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "COMMUNITYPORTAL#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 8)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "SRCHCENTERLITE#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "SRCHCENTERLITE#0" - Language 1033
- }
- }
- elseif($category - eq 2 - and $templateType - eq 9)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "visprus#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "visprus#0" - Language 1033
- }
- }
- elseif($category - eq 3 - and $templateType - eq 1)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "BLANKINTERNETCONTAINER#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "BLANKINTERNETCONTAINER#0" - Language 1033
- }
- }
- elseif($category - eq 3 - and $templateType - eq 2)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "ENTERWIKI#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "ENTERWIKI#0" - Language 1033
- }
- }
- elseif($category - eq 3 - and $templateType - eq 3)
- {
- if ($secondaryAdmin - ne $null)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - SecondaryOwnerAlias $secondaryAdmin - Name $SiteTitle– Description $SiteDescription - Template "PRODUCTCATALOG#0" - Language 1033
- }
- else
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $siteColl = New - SPSite– Url $SiteUrl - OwnerAlias $primaryadmin - Name $SiteTitle– Description $SiteDescription - Template "PRODUCTCATALOG#0" - Language 1033
- }
- }
- else
- {
- write - host "Please select valid Site template" - ForegroundColor Red
- }
- }
- if ($siteColl - ne $null)
- {
- $siteCollUrl = $siteColl.Url
- Write - Host "Site Collection created successfully." - ForegroundColor Green
- Write - Host "Site Collection URL is $siteCollUrl" - ForegroundColor Green
- Write - Host "Create Sub Site under newly created site collection<Y/N>?" - ForegroundColor Yellow
- $createSubSite = read - host
- if ($createSubSite - eq "Y" - or $createSubSite - eq "y")
- {
- CreateSubSite $siteCollUrl
- }
- }
- else
- {
- Write - Host "Error creating Site Collection. Please try again." - ForegroundColor Red
- }
- write - host "Create Another Site Collection under same web aplication<Y/N>?" - foregroundcolor Yellow
- $createSiteColl = Read - Host
- }
- }
- catch [System.Exception]
- {
- Write - Host $_.Exception.ToString()
- }
- }
- functionCreateSubSite([string] $SiteCollUrl)
- {
- try
- {
- $createanotherSubSite = "Y"
- while ($createanotherSubSite - eq "Y" - or $createanotherSubSite - eq "y")
- {
- $featureIdentity = "PublishingSite"
- $SubSiteDescription = $null
- write - host "Please enter the Sub Site Title : " - ForegroundColor Yellow
- $SubSiteTitle = read - host
- write - host "Please enter the Sub Site Description : " - ForegroundColor Yellow
- $SubSiteDescription = read - host
- $SpaceRemovedTitle = $SubSiteTitle - replace " ", ""
- $SiteCollUrlModified = $SiteCollUrl + "/"
- $SubSiteUrl = $SiteCollUrlModified += $SpaceRemovedTitle
- Write - Host $SubSiteUrl
- write - host "Please select the category for Site Template :" - ForegroundColor Cyan
- Write - Host "1 :Collboration Site Templates" - ForegroundColor Yellow
- Write - Host "2 : Enterprise Site Templates" - ForegroundColor Yellow
- $category = Read - Host
- $invalid = $false
- if ($category - eq 1)
- {
- write - host "Please select the Site Template :" - ForegroundColor Cyan
- Write - Host "1: Team Site" - ForegroundColor Yellow
- Write - Host "2: Blog" - ForegroundColor Yellow
- Write - Host "3: Project Site" - ForegroundColor Yellow
- Write - Host "4: Community Site" - ForegroundColor Yellow
- }
- elseif($category - eq 2)
- {
- write - host "Please select the Site Template :" - ForegroundColor Cyan
- Write - Host "1: Document Center" - ForegroundColor Yellow
- Write - Host "2: Records Center" - ForegroundColor Yellow
- Write - Host "3: Business Intelligence Center" - ForegroundColor Yellow
- Write - Host "4: Enterprise Search Center" - ForegroundColor Yellow
- Write - Host "5: Basic Search Center" - ForegroundColor Yellow
- Write - Host "6: Visio Process Repository" - ForegroundColor Yellow
- }
- else
- {
- write - host "Please select valid Site template Category. Try again." - ForegroundColor Red
- $invalid = $true
- }
- if ($invalid - ne $true)
- {
- $templateType = read - host
- if ($category - eq 1 - and $templateType - eq 1)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "STS#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 1 - and $templateType - eq 2)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "BLOG#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 1 - and $templateType - eq 3)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "PROJECTSITE#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 1 - and $templateType - eq 4)
- {
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "COMMUNITY#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 1)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "BDR#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 2)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "OFFILE#1" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 3)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "BICenterSite#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 4)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "SRCHCEN#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 5)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "SRCHCENTERLITE#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- elseif($category - eq 2 - and $templateType - eq 6)
- {
- Write - Host "Enabling Publishing feature on Top Site Collection..Please wait.." - ForegroundColor Yellow
- Enable - SPFeature - identity $featureIdentity - URL $SiteCollUrl - Force
- Write - Host Successfully enabled Publishing feature on Top Site Collection: $SiteCollUrl - ForegroundColor Green
- Write - Host "Please wait..Site Provisioning in Progress.." - ForegroundColor Cyan
- $subsite = New - SPWeb $SubSiteUrl - Template "visprus#0" - Name $SubSiteTitle– Description $SubSiteDescription - UseParentTopNav - Language 1033
- }
- else
- {
- Write - Host "Please select valid Site template" - ForegroundColor Red
- }
- if ($subsite - ne $null)
- {
- Write - Host "Sub Site Created Successfully" - ForegroundColor Green
- Write - Host "SubSite URL is $SubSiteUrl" - ForegroundColor Green
- }
- else
- {
- Write - Host "Error creating SubSite. Please try again." - ForegroundColor Red
- }
- }
- Write - Host "Create another Sub Site under same site collection<Y/N>?" - ForegroundColor Yellow
- $createanotherSubSite = read - host
- }
- }
- catch [System.Exception]
- {
- Write - Host $_.Exception.ToString()
- }
- }
- functionSitecollectionorsubsite
- {
- Write - Host "Please select the choice" - foregroundcolor Cyan
- Write - Host "1. Site Collection" - foregroundcolor Yellow
- Write - Host "2. Sub Site" - foregroundcolor Yellow
- $sitecollorsite = Read - Host
- if ($sitecollorsite - eq 1 - or $sitecollorsite - eq 2)
- {
- return $sitecollorsite
- }
- else
- {
- Write - Host "Please select the valid option and try running script again" - ForegroundColor Red
- return 3
- }
- }
- write - host "Please enter Web Application url" - foregroundcolor Yellow
- $sourceWebURL = Read - Host
- $WebApp = get - spwebapplication $sourceWebURL - ErrorActionsilentlycontinue
- if ($WebApp - eq $null)
- {
- Write - host "Web Application at above url does not Exists. Please Enter valid URL. Try again." - foregroundcolor Red
- }
- else
- {
- Write - host "Successfully validated the web application.." - foregroundcolor Green
- $isrootsiteexist = GetUserInput $sourceWebURL
- if ($isrootsiteexist - eq $true)
- {
- $sitecollorsite = Sitecollectionorsubsite
- while ($sitecollorsite - eq 1 - or $sitecollorsite - eq 2)
- {
- if ($sitecollorsite - eq 1)
- {
- while ($sitecollorsite - eq 1)
- {
- CreateSiteCollection $sourceWebURL
- Write - Host "Create Another Site Collection or Sub Site (Y/N)" - ForegroundColor Yellow
- $anothersitecollorsite = Read - Host
- if ($anothersitecollorsite - eq "Y" - or $anothersitecollorsite - eq "y")
- {
- $sitecollorsite = Sitecollectionorsubsite
- }
- else
- {
- $sitecollorsite = 3
- Write - Host "Thank you!!.." - ForegroundColor Green
- }
- }
- }
- elseif($sitecollorsite - eq 2)
- {
- while ($sitecollorsite - eq 2)
- {
- Write - Host "Please enter the site collection url under which sub site to be created" - ForegroundColor Yellow
- $sitecollurl = Read - Host
- $isSiteExist = GetUserInput $sitecollurl
- if ($isSiteExist - eq $true)
- {
- CreateSubSite $sitecollurl
- }
- else
- {
- write - host "The Site Collection at : $sitecollurl , doesn't exist!!..Please Try again." - ForegroundColor Red
- }
- Write - Host "Create Another Site Collection or Sub Site (Y/N)" - ForegroundColor Yellow
- $anothersitecollorsite = Read - Host
- if ($anothersitecollorsite - eq "Y" - or $anothersitecollorsite - eq "y")
- {
- $sitecollorsite = Sitecollectionorsubsite
- }
- else
- {
- $sitecollorsite = 3
- Write - Host "Thank you!!.." - ForegroundColor Green
- }
- }
- }
- }
- }
- else
- {
- write - host "The Root Site Collection at : $sourceWebURL , doesn't exist!!..Please Try again." - ForegroundColor Red
- }
- }

Ketak BhalsingPosted May 26, 2016, 1:59 AM
Thanks Humayun
Ketak BhalsingPosted May 26, 2016, 1:59 AM
Thanks Debasis
Humayun Kabir MamunPosted May 26, 2016, 1:55 AM
Nice...
Debasis SahaPosted May 26, 2016, 1:18 AM
Good One..
Ketak BhalsingPosted May 26, 2016, 12:57 AM
Thanks Nagaraj
Kuppurasu NagarajPosted May 25, 2016, 1:06 PM
Nice Sharing..