Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Last active June 13, 2023 15:30
Show Gist options
  • Save chrisobriensp/7740710 to your computer and use it in GitHub Desktop.
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)..
. .\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