SharePoint Online: Deactivate a Feature using PowerShell

Requirement: Deactivate a feature in SharePoint Online using PowerShell.

How to Deactivate a Feature in SharePoint Online?

In SharePoint Online, there are times when you may need to deactivate a feature. For example, if you no longer use a feature, or it’s causing problems on your site. In this blog post, We’ll walk you through disabling a SharePoint Online feature. We’ll also share the PowerShell scripts to disable a feature in SharePoint Online. Let’s get started!

Follow these steps to deactivate a SharePoint Online feature:

  1. Navigate to the site where the feature needs to be deactivated.
  2. On the site’s home page, click the Settings gear icon and then the Site Settings option from the Settings menu.
  3. Click the “Manage Site Features” link under the Site Actions section on the Site Settings page.
  4. From the Site Features page, click the “Deactivate” button next to the site feature you desire to deactivate.
  5. The feature status is changed to and the associated feature capabilities are disabled on the site.powershell to disable publishing feature in sharepoint online

Similarly, use the “Site Collection Features” link under the Site Collection Administration section to deactivate a site collection feature.

SharePoint Online PowerShell to Disable Feature:

Here is how to disable a SharePoint Online feature using the Client-Side Object Model and PowerShell.

#Load SharePoint Online CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Function to Disable Feature in SharePoint Online
Function Disable-SPOFeature 
{ 
    param ($SiteCollURL,$UserName,$Password,$FeatureGuid)
    Try 
    {     
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollURL)
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
        $Ctx.Credentials = $Credentials
        $Site=$Ctx.Site

        #Check the Feature Status
        $FeatureStatus =  $Site.Features.GetById($FeatureGuid)
        $FeatureStatus.Retrieve("DefinitionId")
        $Ctx.Load($FeatureStatus)
        $Ctx.ExecuteQuery()

        #Deactivate the feature if its enabled
        if($FeatureStatus.DefinitionId -ne $null)
        {
            Write-Host "Disabling Feature $FeatureGuid..." -ForegroundColor Yellow
            $Site.Features.Remove($FeatureGuid, $true) | Out-Null
            $Ctx.ExecuteQuery()
            Write-Host "Feature has been disabled on site $SiteCollURL!" -ForegroundColor Green
        }
        else
        {
            Write-host "Feature is Not Active on the Site collection!" -ForegroundColor Red
        }
    } 
    Catch
    {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
    }
}
 
#Parameters to Activate Feature
$SiteCollURL = "https://Crescent.sharepoint.com/sites/Demo"
$UserName = "SPAdmin@Crescent.com"
$Password = "Password goes here"
$FeatureGuid= [System.Guid] ("f6924d36-2fa8-4f0b-b16d-06b7250180fa") #Publishing Feature
$SecurePassword= ConvertTo-SecureString $Password -asplaintext -force  

#Disable Feature
Disable-SPOFeature -SiteCollURL $SiteCollURL -UserName $UserName -Password $SecurePassword -FeatureGuid $FeatureGuid

This deactivates the publishing feature using PowerShell in SharePoint Online. This could be helpful if you do not need the feature anymore.

SharePoint Online: Deactivate a Feature using PnP PowerShell

You can disable a feature in SharePoint Online using PowerShell. Let’s disable the publishing feature at the site level using the PnP PowerShell cmdlet Disable-PnPFeature. To achieve this, you will need to connect to your SharePoint Online site using Connect-PnPOnline. Once you are connected, you will need to run the Disable-PnPFeature cmdlet with parameters, the ID of the feature you want to disable, and the scope of the feature. For example, if you want to disable the “Publishing Feature” feature on the “https://crescent.sharepoint.com” site, you would run the following cmdlet: Disable-PnPFeature -Identity “f6924d36-2fa8-4f0b-b16d-06b7250180fa” -scope “Site”.

#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Procurement"
$FeatureId = "f6924d36-2fa8-4f0b-b16d-06b7250180fa" #Site Scoped Publishing Feature

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#get the Feature
$Feature = Get-PnPFeature -Scope Site -Identity $FeatureId 

#Get the Feature status
If($Feature.DefinitionId -ne $null)
{    
    #Deactivate the Feature
    Write-host -f Yellow "Deactivating Feature..."
    Disable-PnPFeature -Scope Site -Identity $FeatureId -Force

    Write-host -f Green "Feature Deactivated Successfully!"
}
Else
{
    Write-host -f Yellow "Feature is Not active!"
} 

Similarly, to disable a feature in SharePoint Online at the web level using PnP PowerShell, use:

#Config Variable
$SiteURL = "https://Crescent.sharepoint.com/Sites/Procurement"
$FeatureId = "94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb" #Web Scoped Publishing Feature

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#get the Feature
$Feature = Get-PnPFeature -Scope Web -Identity $FeatureId 

#Get the Feature status
If($Feature.DefinitionId -ne $null)
{    
    #Activate the Feature
    Write-host -f Yellow "Deactivating Feature..."
    Disable-PnPFeature -Scope Web -Identity $FeatureId -Force

    Write-host -f Green "Feature Deactivated Successfully!"
}
Else
{
    Write-host -f Yellow "Feature is Not active!"
}

How do I activate a site collection feature in PowerShell? To activate a feature in SharePoint Online using PowerShell, refer: How to Activate a Feature in SharePoint Online using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “SharePoint Online: Deactivate a Feature using PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *