Retrieve all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model

Retrieve all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model
InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can retrieve all site templates in SharePoint 2016 using PowerShell and how to retrieve all site templates using SharePoint 2016 server object model.

Using PowerShell:
We ca run the below PowerShell command to retrieve all site templates like below:

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 all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model
Retrieve all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model

Using SharePoint 2016 server object model:
We can also use SharePoint 2016 server object model to retrieve all the site templates.

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:

Retrieve all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model
Retrieve all site templates using PowerShell and retrieve site templates using SharePoint 2016 server object model

Hope this will helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply