Wednesday, June 8, 2016

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)
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteCollURL)
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $Password)
        $Ctx.Credentials = $Credentials

        #Check the Feature Status
        $FeatureStatus =  $Site.Features.GetById($FeatureGuid)

        #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
            Write-Host "Feature has been disabled on site $SiteCollURL!" -ForegroundColor Green
            Write-host "Feature is Not Active on the Site collection!" -ForegroundColor Red
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
#Parameters to Activate Feature
$SiteCollURL = ""
$UserName = ""
$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

You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.

Check out these SharePoint products:

No comments :

Post a Comment

Please Login and comment to get your questions answered!

You might also like:

Related Posts Plugin for WordPress, Blogger...