Powershell: Return SPWebTemplateNameByWebTemplateId
by mysticslayer on Nov.10, 2011, under Powershell, SharePoint 2010, SharePoint Foundation
Sometimes you it’s easy to script some stuff, and you redo some stuff. For example: You want to manually script your export-import action in SharePoint automatically.
Something you need by importing the site is the webtemplate before you can start the import. So, what you can do before deleting the site is to extract the WebTemplateId. The WebTemplate in $web.Url is not sufficient, because it doesn’t translate the correct Configuration.
So, what I’ve did is to use the WebTemplateId and get the according WebTemplate Name. And use it to create a SPSite.
function Get-SPWebTemplateNameBySPWebTemplateId($WebTemplateId) { $templates = Get-SPWebTemplate | Sort-Object "Name" $templateValues | ForEach-Object { if($_.ID -eq $WebTemplateId) $templateName = $_.Name return; } return $templateName } $templateName = Get-SPWebTemplateNameBySPWebTemplateId -WebTemplateId 53 Write-Host = $templateName
Above will return BLANKINTERNET#2