I'm looking for a Powershell script to enable the SharePoint Server Publishing site feature on all sites in a single site collection or all site collections.
2 Answers
To activate the Publishing feature on all the sites in a site collection use the script below. Publishing Infrastructure feature must be enabled for the site collection first.
Get-SPWeb -Site "http://rootWebUrl" -Limit all | % {Enable-SPFeature "PublishingWeb" -url $_.url}
For all site collections in a web application:
foreach ($site in $webApp.Sites)
{
#first enable the Publishing infrastructure feature
Enable-SPFeature "PublishingSite" -url $site.url
Get-SPWeb -Site $site.Url -Limit all | % {Enable-SPFeature "PublishingWeb" -url $_.url}
}
-
this tries to enable the feature at Web level, not site collection level, and fails ,of course, because it's not enabled at site collection level. Nov 25, 2014 at 9:36
-
2@alex-m PublishingSite is a site level feature and PublishingWeb is a web level feature. Nov 25, 2014 at 11:39
For me, this worked better for all sites in a web application. Although I had some sites that already had publishing enabled and I wasn't sure how to skip those.
$sites = Get-SPSite -WebApplication $yourWebApp -Limit All
foreach ($site in $sites)
{
#first enable the Publishing infrastructure feature
Enable-SPFeature "PublishingSite" -url $site.url
Get-SPWeb -Site $site.Url -Limit all | % {Enable-SPFeature "PublishingWeb" -url $_.url}
}