In this SharePoint tutorial we will discuss, how to get SharePoint site template using PowerShell. Also, we will discuss how to get SharePoint site templates programmatically using SharePoint server object model.
If you want to retrieve site templates in SharePoint Online, you can check how to retrieve all site templates available in SharePoint Online using PowerShell.
get sharepoint site template PowerShell
We ca run the below PowerShell command to get SharePoint site template PowerShell in SharePoint 2013/2016 like below:
If you are new to SharePoint PowerShell, then you can read Working with PowerShell in SharePoint Online/2016/2013.
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPWebTemplate
If you want to retrieve in .txt or .csv format then you can write like below:
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPWebTemplate > E:\AllTemplates.txt
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Get-SPWebTemplate > E:\AllTemplates.csv
Retrieve Site Templates using Server Object Model in SharePoint 2013/2016
We can also use SharePoint 2016/2013 server object model to get all the site templates in SharePoint. Here I am using a windows application to display all site templates in SharePoint 2016/2013.
string s = string.Empty;
using (SPSite site = new SPSite(“http://mypc:29024/sites/SPTraining/”))
{
SPWeb web = site.OpenWeb();
SPWebTemplateCollection Templates = site.GetWebTemplates(1033);
foreach (SPWebTemplate template in Templates)
{
s += “Title: ” + template.Title + ” :: Name:” + template.Name + “\n”;
}
}
label10.Text = s.ToString();
Once we run the code, the templates will appear like below:
You may like following SharePoint Online site template tutorials:
- How to find which template is used for a site in SharePoint Online Office 365
- PowerShell SharePoint Examples
- 15+ SharePoint server object model examples
- Bind SharePoint list templates to dropdown list using JavaScript
- Display warning message in SharePoint site using PowerShell
- Save site as template in SharePoint 2013/2016/Online
- SharePoint user custom actions (Designer + Programmatically)
Hope this SharePoint tutorial helps to get sharepoint online site template powershell and Server Object model in SharePoint 2016/2013.
After working for more than 15 years in Microsoft technologies like SharePoint, Office 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (9 times). I have also worked in companies like HP, TCS, KPIT, etc.