Sharepoint - Powershell to get template name site is using
You mean like this?
$web = Get-SPWeb http:/SC/site
$web.WebTemplate + " " + $web.WebTemplateId
$web.close()
The accepted answer is only partly correct. If the question was to get the name of the used web template, the correct answer would be:
$web = Get-SPWeb http:/SC/site
$web.WebTemplate + "#" + $web.Configuration
It seems, Microsoft had an issue (or later added requirement) when implementing these templates, because there is a "background"-id ($web.WebTemplateId
) which presumably denotes the base template used - and there is a "foreground"-id ($web.Configuration
) which is added to the template name, delimited by the # sign.
If you use Get-SPWebTemplate, you can see that all the three STS Templates have the same "background"-id but different "foreground"-ids in their name:
PS C:\WINDOWS\system32> Get-SPWebTemplate -Identity "STS#0" | Select-Object Name,Id
Name ID
---- --
STS#0 1
PS C:\WINDOWS\system32> Get-SPWebTemplate -Identity "STS#1" | Select-Object Name,Id
Name ID
---- --
STS#1 1
PS C:\WINDOWS\system32> Get-SPWebTemplate -Identity "STS#2" | Select-Object Name,Id
Name ID
---- --
STS#2 1
For Webs of all three types, using $web.WebTemplateId
will always be 1 ("background"-id) and the value in $web.Configuration
will vary according to the template and be 0, 1 or 2 ("foreground"-id).
So, to get the name of the used template, the correct field for the template number would be $web.Configuration
, not $web.WebTemplateId
.