Export All Sites and Sub Sites with Templates

Note: There are more simpler ways to do that but this script is more batch proess.

if((Get-PSSnapin -Name Microsoft.Sharepoint.PowerShell -ErrorAction SilentlyContinue) -eq $null) {  Add-PSSnapin Microsoft.Sharepoint.PowerShell } 

$outputFile = "E:\Scripts\Communityportal.csv"
$outputFileAll = "E:\Scripts\AllSitesHierarcy.csv"
$Sites = @(); 

$webApp = Get-SPWebApplication 

foreach($webApp in Get-SPWebApplication)
  Write-Host "Web Application : " + $webApp.Name 

  foreach($spSite in $webApp.Sites)
     if($spSite -ne $null)
       foreach ($spWeb in $spSite.AllWebs)
           $TempalteID = $spWeb.WebTemplateId
           $Tempalte = $spWeb.WebTemplate
           write-host "Web Template:" $Tempalte  "| Web Template ID:" $TempalteID
           $csv = new-object PSObject
           add-member -InputObject $csv NoteProperty "WebURL" $spWeb.Url
           add-member -InputObject $csv NoteProperty "WebTemplate" $Tempalte
           add-member -InputObject $csv NoteProperty "WebTemplateId" $TempalteID
           $Sites +=$csv
$Sites | Export-Csv -path $outputFileAll -notypeinformation
$Sites | ? WebTemplate -like "CommunityPortal*" | Export-Csv -path $outputFile -notypeinformation
$Sites | Out-GridView

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s