kwizcom banner advertisement

SharePoint Online: Deactivate Feature using PowerShell

Requirement: Deactivate a feature in SharePoint online using PowerShell.

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.
powershell to disable publishing feature in sharepoint online

SharePoint Online: Deactivate a Feature using PnP PowerShell 
#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 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.