SharePoint Online: Deactivate Feature using PowerShell

Requirement: Deactivate a feature in SharePoint online using PowerShell.

How to Deactivate a Feature in SharePoint Online?
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 Site Settings option from the Settings menu.
  3. On the Site Settings page, Click the "Manage Site Features" link under Site Actions section.
  4. On 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 in the site.powershell to disable publishing feature in sharepoint online
Similarly, to deactivate a site collection feature, use the link "Site Collection Features" under Site Collection Administration section.

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 publishing feature using PowerShell in SharePoint Online.

SharePoint Online: Deactivate a Feature using PnP PowerShell 
Let's disable publishing feature at site level:
#Config Variable
$SiteURL = "https://crescenttech.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 web level using PnP PowerShell, use:
#Config Variable
$SiteURL = "https://crescenttech.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!"
}
SharePoint Online: Deactivate Feature using PowerShell SharePoint Online: Deactivate Feature using PowerShell Reviewed by Salaudeen Rajack on June 08, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.