2

I am working with a lot of site collections, which each have many subsites. I have custom branding that will only work if the publishing feature is activated on each site and subsite. I tried this:

$sites = Get-SPSite -WebApplication "https://myWebApp.com/" -Limit All foreach ($site in $sites) { Enable-SPFeature "PublishingSite" -url $site.url }

That only activated publishing on all the root site collections, not the subsites. So then I tried adding this in the loop:

Get-SPWeb -Site $site.Url -Limit all | % {enable-SPFeature "PublishingSite" -url $_.url}

When I did that I got this error:

The specified feature applies to the entire site collection, but the specified URL refers to a particular sub site. To apply this feature to the entire site collection, use the root URL 'https://myWebApp.com/sites/aSiteCollection'

What do I need to change so that every "SPWeb" can have the publishing feature activated?

1

You need to modify the web level feature name to PublishingWeb.

Change the SPWeb level code as below:

Get-SPWeb -Site $site.Url -Limit all | % {enable-SPFeature "PublishingWeb" -url $_.url}

Publishingsite is the SharePoint server Publishing infrastructure feature at site collection level. Its present only at the site collection.

PublishingWeb is the SharePoint server Publishing feature at the subsite level.This is present only at SPWeb level.

  • @Adam - did you try this ? is it working for you, if yes , can you please mark it as answer ? – Gautam Sheth Nov 1 '17 at 10:13
1

Try this code:

Activate web scoped feature for all sites in a site collection
$site = Get-SPSite http://portal
$site | Get-SPWeb -limit all | ForEach-Object {Enable-SPFeature -Identity "PublishingWeb" -Url $_.Url}
$site.Dispose()

Reference: Add SharePoint farm solution and bulk activate feature using PowerShell

  • Is it necessary to Dispose of the variable? – Adam Gehring Nov 2 '17 at 4:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.