0

I have created site collection.under this site collection I need to create another subsite.the site template for subsite is custom template which is uploaded via solution gallery. how can I achive this using powershell script?

1 Answer 1

2

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 Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\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().

courtesy : https://blogs.technet.microsoft.com/fromthefield/2015/10/21/create-a-subsite-web-using-a-custom-template-in-sharepoint-online-using-powershell-and-csom/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.