Search This Blog

Sunday, January 22, 2012

Powershell script to get all site templates in the sharepoint farm : SharePoint 2010

Sometimes , we want to know the template name of the site if we need to create the site from a template using code or powershell script.

The names of all the templates in a sharepoint farm can be obtained by executing the following powershell command let :
Get-SPWebTemplate | Sort-Object "Name"

However, if we want additional information for each web template like its id, we can use the following powershell script to iterate over all the web templates and add them to a new powershell 'PSObject':

function Get-SPWebTemplateWithId
{
    $templates = Get-SPWebTemplate | Sort-Object "Name"
    $templates | ForEach-Object {
        $templateValues = @{
            "Title" = $_.Title
            "Name" = $_.Name
            "ID" = $_.ID
            "Custom" = $_.Custom
            "LocaleId" = $_.LocaleId
        }
        New-Object PSObject -Property $templateValues | Select @("Name","Title","LocaleId","Custom","ID")
    }
}
Get-SPWebTemplateWithId | Format-Table

This powershell script will give the following output:



No comments:

Post a Comment