Tuesday, November 20, 2012

Enable the SharePoint Server Publishing Feature in SharePoint 2010 using Powershell

To use the SharePoint Server publishing feature in a SharePoint site, we need to activate the PublishingSite in site collection level as a first step and finally activate the publishing web to all webs in that site collection.


Script to Activate the SharePoint Server Publishing Feature

#Step 1: The SharePoint Server Publishing Infrastructure Feature needs to be enabled in site collection level
$PublishingSitefeature = Get-SPFeature PublishingSite #where the PublishingSite is the inernal name of the SharePoint Server Publishing Infrastructure Feature
write-host "The feature name is " $PublishingSitefeature.DisplayName
$siteCollection = Get-SPSite $siteUrl #Into Site Collection level
write-host "Activating " $PublishingSitefeature.DisplayName " on "  $siteCollection.Url
Enable-SPFeature $PublishingSitefeature -Url $siteCollection.Url #Enable the feature to the site collection
write-host "Activated " $PublishingSitefeature.DisplayName " on "  $siteCollection.Url
$siteCollection.Dispose()

#Step 2: Then enable the SharePoint Server Publishing feature to all webs in Site collection.
$siteCollection = Get-SPSite $siteUrl #Into Site Collection level
$siteCollection | Get-SPWeb -limit all | ForEach-Object{
write-host "Activating the PublishingWeb feature on " $_.Url
Enable-SPFeature -Identity "PublishingWeb" -Url $_.Url #where the PublishingWeb is the internal name of the SharePoint Server Publishing feature
write-host "Activated the PublishingWeb feature on " $_.Url
}
$siteCollection.Dispose()

#Note: Publishing feature needs to be enabled in site collection before enabling it to all the webs

2 comments:

  1. Awesome. Definitely saves my day :)
    One code-performance improvement could be to check if the features are pre-enabled or not.
    But thanks for posting the entire piece.

    ReplyDelete