Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Last active September 12, 2017 13:04
Show Gist options
  • Save chrisobriensp/7685240 to your computer and use it in GitHub Desktop.
Save chrisobriensp/7685240 to your computer and use it in GitHub Desktop.
PS + CSOM to activate/deactivate a Feature (e.g. in SharePoint Online)..
. .\TopOfScript.ps1
[bool]$enable = $true
[bool]$force = $false
# using the Minimal Download Strategy Feature here..
$FeatureId = [GUID]("87294C72-F260-42f3-A41B-981A2FFCE37A")
# ..and working with the web-scoped Features - use $clientContext.Site.Features for site-scoped Features
$webFeatures = $clientContext.Web.Features
$clientContext.Load($webFeatures)
$clientContext.ExecuteQuery()
if ($enable)
{
$webfeatures.Add($featureId, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
}
else
{
$webfeatures.Remove($featureId, $force)
}
try
{
$clientContext.ExecuteQuery()
if ($enable)
{
Write-Host "Feature '$FeatureId' successfully activated.."
}
else
{
Write-Host "Feature '$FeatureId' successfully deactivated.."
}
}
catch
{
Write-Error "An error occurred whilst activating/deactivating the Feature. Error detail: $($_)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment