Apply Publishing Feature to all Subsites with Powershell Sharepoint 2016
-
04-01-2021 - |
Вопрос
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?
Решение
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.
Другие советы
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