André Krijnen

Powershell: Return SPWebTemplateNameByWebTemplateId

by 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


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...