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
$siteUrl = "http://sharePoint/sites/projects/testproject1"
$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.
$siteUrl = "http://sharepoint/sites/projects/testproject1"
$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