Get SharePoint Online Site and List Templates using PowerShell

Site collection templates in SPO
SharePoint deveopment training course

This PowerShell SharePoint tutorial explains, how to get SharePoint Online site and list templates using PowerShell.

This SharePoint Online tutorial, we will discuss how to retrieve all site templates available in SharePoint Online using PowerShell. We will retrieve the site template id and site template name in SharePoint Online using PowerShell.

We will also discuss how to retrieve all SharePoint Online list templates using PowerShell.

You can write and debug the PowerShell script in Windows PowerShell ISE or you can also write in Visual Studio code.

Get all site templates using PowerShell in SharePoint Online

We all know that these days Microsoft is more focused on expanding SharePoint Online scope and abilities widely. Let me share some of my knowledge to add an extra feather in your crown. To start up with SPO (SharePoint Online) we need to know what are the various site collection templates available for us.

In SharePoint on-premise environment we will have more than 100 templates that support both SharePoint 2010/2013 or SharePoint 2016 with the compatibility modes as 14 & 15, but in SharePoint Online we will max 16 templates.

With the below PowerShell script, you can see all the available web templates in SharePoint Online Office 365.

try {
function get-SPOnlineWebTemplates {
#SharePOint Online Admin Site URL
$adminUrl = "<<Sharepoint SPO Admin site URL>>"
#SharePoint Online Admin ID
$userName = "<<SharePoint SPO admin account>>"
#reading password from command prompt
$password = Read-Host "Please the Password for Admin account" -AsSecureString
#set credentials for SharePoint Online
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $userName, $password
#connect to SharePoint Online
Connect-SPOService -Url $adminUrl -Credential $credentials
#Fetching all the Site template Names
get-spoWebTemplate | select @{N = 'Template ID'; E = {$_.Name}}, @{N = 'Template Name'; E = {$_.Title}}, @{N = 'Compatibility Level'; E = {$_.CompatibilityLevel}}
}
get-SPOnlineWebTemplates
}
catch {
Write-Host "`nError:: $($_.Exception.Message)" -foregroundcolor red -BackgroundColor Yellow
}

In the above script I am changing column name with the alias as follows:

select @{N = 'Template ID'; E = {$_.Name}}

In this statement, Template ID is alias name and the actual column name is Name.

The output with the list of site template is as follows:

Retrieve all site templates using PowerShell in SharePoint Online

Get all List Templates using PowerShell in SharePoint Online

As we know that we have some variation between SharePoint on-premise and SharePoint Online, it is always good to know what available list of templates in SharePoint Online are? Here we will show how to retrieve SharePoint Online list templates using PowerShell.

For ease of access, I have implemented the below PowerShell script which will display a list of available templates in SharePoint Online.

function get-SPOListTemplates
{
#Variables that needs to be set before starting the script
$strSiteURL = "<< Site URL >>"
$strUsrName = "<< User Name >>"

# Reading password for the user account
$strPWD = Read-Host "Please enter the password for $($strUsrName)" -AsSecureString

# set SharePoint Online credentials
$SPOCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($strUsrName, $strPWD)

# Creating client context for the provided user name and password
$objContext = New-Object Microsoft.SharePoint.Client.ClientContext($strSiteURL)
$objContext.credentials = $SPOCredentials
$LstTempColl = $objContext.web.listtemplates
$objContext.load($LstTempColl)

#Sending the request to pull all the list templates
try{
$objContext.executeQuery()
write-host "The list of templates available in SPO:" -foregroundcolor white -backgroundcolor red
}
catch{
write-host "info: $($_.Exception.Message)" -foregroundcolor red
}

#List templates available in SPO
#$LstTempColl | select baseType, Description, ListTemplateTypeKind | ft -wrap # This will show the full description of the list template description
$LstTempColl | select baseType, Description, ListTemplateTypeKind
}
get-SPOListTemplates

The output is as follows:

Retrieve all List Templates using PowerShell in SharePoint Online

You may like following SharePoint tutorials:

This PowerShell tutorial, we learned how to get all site templates using PowerShell in SharePoint 2013/2016. Also, we saw how to get all list templates using PowerShell in SharePoint 2013/2016.

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Krishna Vandanapu

I am Krishna.Vandanapu a SharePoint architect working in IT from last 13+ years, I worked in SharePoint 2007, 2010, 2013, 2016 and Office 365. I have extensive hands on experience in customizing SharePoint sites from end to end. Expertise in SharePoint migration tools like Sharegate, Doc Ave and Metalogix. Migrated SharePoint sites from SharePoint 2007 to 2010 and 2010 to 2013 several times seamlessly. Implementing CSOM with Microsoft best practices. Spent quality time in configuring SharePoint application services like User Profile, Search, Managed Meta data services etc. Now exploring SharePoint Framework and SharePoint 2019

View all posts by Krishna Vandanapu →