Create a SharePoint Subsite from Custom Site Template using PowerShell

Requirement: We have a PMO site template created for managing projects in SharePoint. Had a new requirement to create some 20+ new PMO subsites based on the custom site template.

To create a site based on site template, you can pick the custom tab and then select appropriate site template from the list.

Create a SharePoint Subsite from Custom Site Template using PowerShell

PowerShell script to create a subsite from custom site template:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Custom function to create a site from site template
Function Create-SubsiteFromTemplate($SiteTitle, $ParentSiteUrl, $TemplateTitle)
    #Get the custom site template
    $ParentWeb = Get-SPWeb $ParentSiteUrl
    $SiteTemplates = $ParentWeb.GetAvailableWebTemplates($ParentWeb.Language)

    $CustomSiteTemplate = $SiteTemplates | Where-Object {$_.Title -eq $CustomSiteTemplateTitle}

    #URL for you new subsite
    $SiteUrl = $ParentSiteUrl + $SubsiteURL

    #create subsite without template
    $web  = New-SPWeb -Name $SiteTitle -Url $SiteUrl 

    #Apply the custom site template

    Write-host "Subsite $($web.Url) has been created from template!"

#Call the function to create subsite
Create-SubsiteFromTemplate "Airbus 365 Project" ""  "PMO Site Template"

This creates s subsite “Airbus 365 Project” with URL “airbus365project” at the parent site: with template “PMO Site Template”.

How to create a subsite in bulk from a custom site template?

#List of sites to be created
$ProjectList = @("Data Tools", "Knowledge Village", "Service Center", "Business Reporting", "JDT Core", "EFI", "Ecore Tools")
$ParentSiteURL =""
$SiteTemplateTitle = "PMO Site Template"

#loop through each object in the array and create subsite
foreach($Project in $ProjectList)
    #Call the function to create subsite
    Create-SubsiteFromTemplate $project $ParentSiteURL $SiteTemplateTitle    

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “Create a SharePoint Subsite from Custom Site Template using PowerShell

  • July 24, 2017 at 12:30 PM

    I do trust all of the ideas you have presented in your post.
    They are really convincing and can certainly
    work. Nonetheless, the posts are very short for beginners.
    May just you please extend them a bit from next time? Thank you for the post.

  • October 18, 2016 at 12:06 AM

    am getting the error:
    New-SPWeb : The Web site address “/sites/dms” is already in use.
    At C:createsubsitefromsitetemplate.ps1:20 char:22
    + $web = New-SPWeb <<<< -Name $SiteTitle -Url $SiteUrl + CategoryInfo : InvalidData: (Microsoft.Share....SPCmdletNewWeb:SPCmdletNewWeb) [New-SPWeb], SPException + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewWeb You cannot call a method on a null-valued expression. At C:createsubsitefromsitetemplate.ps1:23 char:26 + $Web.ApplyWebTemplate <<<< ($CustomSiteTemplate.Name) + CategoryInfo : InvalidOperation: (ApplyWebTemplate:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

    • March 19, 2017 at 11:41 AM

      Apparently, the error message says the New-SPWeb already exists! So if you want to apply custom web template on existing sites, use:
      $web = Get-SPWeb


Leave a Reply