Last active
June 13, 2023 15:30
-
-
Save chrisobriensp/7740710 to your computer and use it in GitHub Desktop.
PS + CSOM to enable side-loading in SP2013 (e.g. to deploy apps to a site NOT created with the Developer Site template)..
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 | |
# this is the side-loading Feature ID.. | |
$FeatureId = [GUID]("AE3A1339-61F5-4f8f-81A7-ABD2DA956A7D") | |
# ..and this one is site-scoped, so using $clientContext.Site.Features.. | |
$siteFeatures = $clientContext.Site.Features | |
$clientContext.Load($siteFeatures) | |
$clientContext.ExecuteQuery() | |
if ($enable) | |
{ | |
$siteFeatures.Add($featureId, $force, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) | |
} | |
else | |
{ | |
$siteFeatures.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