Get Site Templates in SharePoint Online using PowerShell

Requirement: Get Site Templates in SharePoint Online using PowerShell.

How to Get Site Templates in SharePoint Online?
Site templates are the building blocks of sites in SharePoint Online. They define the structure, data, functionality, and look and feel of the site. SharePoint Online provides different site templates out-of-box to quickly create sites. The "Template Selection" section in the create site page gives you the list of site templates in SharePoint Online.
sharepoint online get web template

You need the site template in order to create sites in SharePoint. Picking the site template from the web user interface is fine, but how to get site template in SharePoint Online from PowerShell?

PowerShell to Get Site Template in SharePoint Online
You need the site template ID when you create a site or site collection in SharePoint Online. Here is the PowerShell to get site templates in SharePoint Online. The Get-SPOWebTemplate cmdlet gets you the SharePoint Online site template list.
#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Get site template list
Get-SPOWebTemplate
This retrieves SharePoint Online site template ID list for PowerShell:
get site template sharepoint online powershell
While the above PowerShell cmdlet gives you the list of all OOTB site templates, how to get custom site templates?

SharePoint Online: Get Custom Site Templates using PowerShell
Here is how to get site templates in SharePoint Online using PowerShell:
#Load SharePoint Online Assemblies
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"

#Set parameter values
$SiteURL = "https://crescenth.sharepoint.com"

$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
 
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
         
#Get the Custom Site Template
$SiteTemplates = $Ctx.Site.GetWebTemplates("1033","0")
$Ctx.Load($SiteTemplates)
$Ctx.ExecuteQuery()

#Remove all users from the group
ForEach($Template in $SiteTemplates)
{
    $Template | Select Name, ID, Description
}

PnP PowerShell to Get SharePoint Online Site Templates
The "Get-PnPWebTemplates" cmdlet in SharePoint Online retrieves all default web templates. Lets use PnP PowerShell get site templates in SharePoint online, including custom site templates.
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com/"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Context & Web Objects
$ClientContext = Get-PnPContext
$Web = Get-PnPWeb

#Get All Web Templates
$WebTemplateCollection = $Web.GetAvailableWebTemplates(1033,0)
$ClientContext.Load($WebTemplateCollection)
$ClientContext.ExecuteQuery()

#Get the Template Name and Title
$WebTemplateCollection | Select Name, Title
This gets you the SharePoint Online site template id list using PnP PowerShell.
Name Title
BDR#0 Document Center
BICenterSite#0 Business Intelligence Center
BLANKINTERNETCONTAINER#0 Publishing Portal
BLOG#0 Blog
COMMUNITY#0 Community Site
COMMUNITYPORTAL#0 Community Portal
DEV#0 Developer Site
EHS#1 Team Site - SharePoint Online configuration
ENTERWIKI#0 Enterprise Wiki
OFFILE#1 Records Center
PRODUCTCATALOG#0 Product Catalog
PROJECTSITE#0 Project Site
SITEPAGEPUBLISHING#0 Communication site
SRCHCEN#0 Enterprise Search Center
SRCHCENTERLITE#0 Basic Search Center
STS#0 Team site (classic experience)
STS#3 Team site (no Office 365 group)
visprus#0 Visio Process Repository

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.