How to activate publishing feature in SharePoint 2013/2016 using PowerShell Script

This SharePoint 2013 tutorial, we will discuss how to activate publishing feature in SharePoint 2013/2016 using PowerShell. We can also manually activate publishing feature in SharePoint 2013/2016.

If you have created any site which is not a publishing site, then you can activate the publishing feature in the team sites or any other sites.

Here we will see different ways to activate publishing feature in SharePoint 2013/2016.

  • Activate publishing feature manually using Browser
  • Activate publishing feature using PowerShell

Activate publishing feature manually using Browser in SharePoint 2013/2016

We can easily activate SharePoint publishing feature manually using browser in SharePoint 2013/2016.

Navigate to SharePoint Site Settings >> Click on “Site collection features” link under “Site collection administration“. Click on “Activate” button next to “SharePoint Server Publishing Infrastructure

activate publishing feature sharepoint 2013
activate publishing feature sharepoint 2013

Activate publishing feature SharePoint 2013/2016 PowerShell

Now, we will see how we can activate publishing feature in SharePoint 2013/2016 using PowerShell. If you are new to PowerShell, check out PowerShell SharePoint tutorial.

Below is the PowerShell script which will activate the publishing feature in site collection and all its sub sites in SharePoint 2013/2016.

You can write, debug, test the PowerShell script using visual studio code or using windows PowerShell ISE.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Variables
$WebAppURL="http://hqRajdev13/"
$SiteFeatureName = "PublishingSite"
$WebFeatureName = "PublishingWeb"
 
#Get all site collections of the web app and iterate through
$SiteColl= Get-SPSite -WebApplication $WebAppURL -Limit ALL
Foreach($Site in $SiteColl)
{
    write-host "Processing site collection:"$Site.URL -ForegroundColor Yellow
    #Check if publishing feature is already activated in the site
    $Feature = Get-SPFeature -Site $Site.URL | Where-object {$_.DisplayName -eq $SiteFeatureName}
 
    if($Feature -eq $null)
    {   
        #Enable the Publishing feature
        Enable-SPFeature -Identity $SiteFeatureName -url $Site.URL -Confirm:$False
    
        Write-host "Publishing Feature Activated on $($Site.URL)" -ForegroundColor Green   
    }
    else
    {
        Write-host "Publishing Feature is already Active on $($Site.URL)" -ForegroundColor Red
    }
 
    #Loop through each web in the site collection
    Foreach($Web in $Site.AllWebs)
    {
        write-host "Processing Web"$Web.URL -ForegroundColor Yellow
        #Check if publishing feature is already activated in the web
        $Feature = Get-SPFeature -Web $Web.URL | Where-object {$_.DisplayName -eq $WebFeatureName}
        if($Feature -eq $null)
        {   
            #Enable the Publishing feature
            Enable-SPFeature -Identity $WebFeatureName -url $Web.URL -Confirm:$False
    
            Write-host "Publishing Feature Activated on $($Web.URL)" -ForegroundColor Green   
        }
        else
        {
            Write-host "Publishing Feature is already Active on $($Web.URL)" -ForegroundColor Red
        }
    }
}
Activate publishing feature SharePoint 2013 PowerShell
Activate publishing feature SharePoint 2013 PowerShell

Note: You need to update your web Application URL instead of the above-given URL. The few of the line is showing an error because I given the TEST URL. Once you update the correct URL, then the code will execute fine as I tested this code properly in my Machine.

You may like following PowerShell SharePoint tutorials:

Reference: https://www.sharepointdiary.com/2016/03/activate-publishing-feature-using-powershell-in-sharepoint.html

Hope this SharePoint tutorial helps how to activate publishing feature in SharePoint 2013/2016 using PowerShell or manually using browser.

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

Rajkiran Swain

Rajkiran is currently working as a SharePoint Consultant in QATAR . Rajkiran having 6 + years of experience in Microsoft Technologies such as SharePoint 2019/2016/2013/2010, MOSS 2007,WSS 3.0, Migration, Asp.Net, C#.Net, Sql Server, Ajax, jQuery etc.He is C#Corner MVP (2 Times).

  • […] to activate publishing feature in SharePoint 2013/2016 using PowerShell […]

  • […] to activate publishing feature in SharePoint 2013/2016 using PowerShell […]

  • […] to activate publishing feature in SharePoint 2013/2016 using PowerShell […]

  • Kiran says:

    Excellent Rajkiran.. May I just copy-paste this script to my blog and claim it as mine – without giving credits to you?

  • >