Saturday, January 3, 2015

SharePoint Online: Activate Feature using PowerShell

Requirement: Activate a feature in SharePoint online site collection using PowerShell.

Solution: In SharePoint On-Premises, We use: Enable-SPFeature cmdlet to activate/enable features. In SharePoint online there is no such cmdlet available through PowerShell to activate feature. But we can utilize Client Side Object Model (CSOM) to activate feature in SharePoint online. Lets activate "SharePoint Server Publishing Infrastructure" feature

Make sure you have SharePoint Server 2013 Client Components SDK installed in your machine to use Client side assemblies. You can download it from:

SharePoint online: PowerShell script to enable feature
#Load SharePoint CSOM Assemblies
Import-Module Microsoft.Online.SharePoint.Powershell

#Variables for Processing
$SiteURL = ""
$FeatureGUID =[System.GUID]("f6924d36-2fa8-4f0b-b16d-06b7250180fa") #Publishing Feature ID
$LoginName =""
$LoginPassword ="Password" 

#Get the Client Context
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)

#Login Credentials
$SecurePWD = ConvertTo-SecureString $LoginPassword –asplaintext –force  
$Credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $LoginName, $SecurePWD
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credential.UserName,$Credential.Password)

#Get the Site
$site = $

#Enable the Feature
$site.Features.Add($FeatureGUID, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::farm)    

#To Disable a Feature use:
#$site.Features.Remove($FeatureGUID, $force);  

write-host "Feature has been Activated!" 

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...