SharePoint PowerShell to Pull Information about template used in the subsite/webs

There might a request for you to provide the web template within your sharepoint environment. in scenario, like you're doing SharePoint 2010 migration and you'd like to know the distribution of the web template used within your sharepoint farm.

The following PowerShell will be able to give the necessary information by enumerating all the site collections in the farm. And for each site collection, it will enumerate each subwebs in the site collection And it will display information related to site/webURL, title, template and template ID use. It will output the result to CSV file in the current directory where you rrun this script. with date time stamp on it, so you can run the powershell and make necessary comparison as you look back with the previous results.

$site = get-spsite
$sitecount = $site.count
$date = get-date -uformat "%Y%m%d"
$filename = "sitetemplate_$date.csv"
"Enumerating List of sites and subwebs" | Out-File -FilePath $filename
for ($i=0;$i -lt $sitecount;$i++)
 {
    
     $webinthisite = $site[$i].AllWebs
     $webscount = $webinthisite.count
     #"$i $site[$i].Url  $webscount subwebs" | Out-File -FilePath $filename -Append
     "SiteURL - SiteTemplateName - SiteTemplateId" | Out-File -FilePath $filename -Append
        for ($j=0;$j -lt $webscount;$j++)
            {
                $siteTitle = $webinthisite[$j]
                $siteUrl = $webinthisite[$j].Url
                $siteTemplate = $webinthisite[$j].WebTemplate  
                $siteTemplateID = $webinthisite[$j].WebTemplateID                
                $str = "$siteUrl - $siteTitle - $siteTemplate - $siteTemplateID" | Out-File -FilePath $filename -Append           
            }
            "===================================================" |  Out-File -FilePath $filename -Append
            $webinthissite.dispose
 }

You might need to adjust as neessary to pull-out other data that suits your requirements. Hopefully it’s useful for your deployment project.