Thursday, February 23, 2017

Get All Web Templates Using PowerShell SharePoint 2013

This script will traverse all the site collections and extract its template name.

1.Site Collections File

Create text file with name “SiteCollections.txt” in the same directory where script file is present.
Write site collections urls in “SiteCollections” file. 
Make it sure each url should be in new line and write “End Point” at the end as shown below.


2. Save Code and Run
Save below code and Open SharePoint Management Shell. Change the directory to where the code and SiteCollections.txt file is saved and run the code script file.

The output would be like below.


PS Script:

[code] $currentTime = Get-Date -Format o | foreach {$_ -replace ":", "."} New-Item $PSScriptRoot\GetAllWebTemplates-$currentTime.txt -type file $SiteCollectionArray = Get-Content -Path $PSScriptRoot\SiteCollections.txt Start-Transcript -Path "$PSScriptRoot\GetAllWebTemplates-$currentTime.txt" $UtilStartTime = "Utility Start Time: " $startTime = Get-Date -Format F $UtilStartTime + $startTime foreach ($url in $SiteCollectionArray) { if($url -ne "End Point") { try{ $site=Get-SPSite -Identity $url } catch {} foreach($web in $site.AllWebs) { if($web) { $output = $site.URL + "`t" + $web.URL + "`t" + $web.WebTemplate + "`t" + $web.WebTemplateId Write-Output $output $web.Dispose() } else { Write-Output "Site Doesn't exist" } } } } $UtilEndTime = "Utility End Time: " $endTime = Get-Date -Format F $UtilEndTime + $endTime Stop-Transcript [/code]

1 comment:

  1. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Isoft Innovations Adyar
    Isoft Innovations Facebook

    ReplyDelete