Wednesday 9 April 2014

Powershell script to get the report of Templates associated with the Sites in Sharepoint

Steps:

1) Open the Notepad or "Windows Powershell ISE" if you have this installed in your machine
2) write the below code

Script:
1:  Add-PsSnapin Microsoft.SharePoint.PowerShell  
2:  $siteURL = read-host "Enter the URL of the Site Collection to identify the templates used by each site"  
3:  $site = Get-SPSite $siteURL  
4:   foreach ($web in $site.AllWebs)  
5:   {  
6:     $SiteTitle = $web.Title  
7:     $SiteName = $web.Name  
8:     $SiteTemplate = $web.WebTemplate  
9:     $TemplateID = $web.WebTemplateID  
10:     write-host "$SiteTitle ,$SiteName ,$SiteTemplate ,$TemplateID "  
11:   }  
12:   $site.Dispose()  
13:  Remove-PsSnapin Microsoft.SharePoint.PowerShell  

3) If the script is written in Notepad, then save the file with .ps1 extension
4) The script file can be executed either using the "Windows Powershell" or using a batch file with .bat extension
5) If you want to execute the script with a single click using a batch file, please find the below code for batch file

Code:

1:  cd /d %~dp0  
2:  powershell -noexit -file  ".\GetTemplatesbyURL.ps1" "%CD%" >> "c:\site templates.csv"  
3:  pause  

Note: In the above batch file give the output file name for ex: c:\site templates.csv, so that the output can be saved for future reference.

In order to check the template associated for a specific site instead of all webs in Site Collection, we don't have to execute any Powershell command, rather open the site ->Right Click on the page -> view page source -> search for g_wsaSiteTemplateId to get the template ID.


No comments:

Post a Comment