Last active
September 12, 2017 13:04
-
-
Save chrisobriensp/7685240 to your computer and use it in GitHub Desktop.
PS + CSOM to activate/deactivate a Feature (e.g. in SharePoint Online)..
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. .\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