Sharepoint - How to get list of available custom template name using powershell script
I have answered for the same kind of query , Please find below the detail to get the available custom templates and create a sub-site based on that .
This can be achieved using power shell and CSOM by following below steps .
Once the custom template is uploaded into the solution gallery of the site collection execute the below commands in Powershell:
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web ServerExtensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web ServerExtensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$Site = "SiteCollectionURL"
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
List Custom Templates
$Templates = $Context.Site.GetWebTemplates("1033","0")
$Context.Load($Templates)
$Context.ExecuteQuery()
$Templates | Where {$_.Name -like "*{*" } | Select Name, Description
This will list out all the custom templates available in the gallery.
And execute the below commands to create the subsite using the custom template:
Create Sub-Web using the Custom Template
$WCI = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$WCI.WebTemplate = "{516EB07D-8711-4B9F-A3AD-097B28C5CDDF}#MyCustomTemplate"
$WCI.Description = "MyNewSubSite"
$WCI.Title = "MyNewSubSite"
$WCI.Url = "MyNewSubSite"
$WCI.Language = "1033"
$SubWeb = $Context.Web.Webs.Add($WCI)
$Context.ExecuteQuery().
This should help
$web = get-spweb http://intranet
$template = $web.GetAvailableWebTemplates(1033)
To create a new subsite, based off of a custom web template, you can use the following script
$web = get-spweb http://intranet
$template = $web.GetAvailableWebTemplates(1033) | Where-Object {$_.Name -eq "My Custom Template Name"}
New-SPWeb -Url "http://intranet/site1" -Name "Site 1" –Template $template
Try the below code, will give you a list of all available templates. Using this, you can find out the custom template name as well as its ID
function Get-SPWebTemplateWithId
{
$templates = Get-SPWebTemplate | Sort-Object "Name"
$templates | ForEach-Object {
$templateValues = @{
"Title" = $_.Title
"Name" = $_.Name
"ID" = $_.ID
"Custom" = $_.Custom
"LocaleId" = $_.LocaleId
}
New-Object PSObject -Property $templateValues | Select @("Name","Title","LocaleId","Custom","ID")
}
}
Get-SPWebTemplateWithId | Format-Table