Skip to content

Instantly share code, notes, and snippets.

@kliemohn
Last active February 1, 2017 21:28
Show Gist options
  • Save kliemohn/da614c2bda9f34d58daac9840fede8f1 to your computer and use it in GitHub Desktop.
Save kliemohn/da614c2bda9f34d58daac9840fede8f1 to your computer and use it in GitHub Desktop.
#Definition of the function that allows to enable a SPO Feature
function Enable-SPOFeature
{
param ($sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
try
{
#Adding the Client OM Assemblies
#TODO - copy assemblies to the folder specified below
Add-Type -Path "C:\Temp\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Temp\Microsoft.SharePoint.Client.Runtime.dll"
#SPO Client Object Model Context
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
$spoCtx.Credentials = $spoCredentials
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Enabling the Feature with GUID $sFeatureGuid !!" -ForegroundColor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$guiFeatureGuid = [System.Guid]$sFeatureGuid
$spoSite=$spoCtx.Site
$spoSite.Features.Add($sFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
$spoCtx.ExecuteQuery()
$spoCtx.Dispose()
}
catch [System.Exception]
{
write-host -f red $_.Exception.ToString()
}
}
#Required Parameters 
$sSiteColUrl = "https://mycompany.sharepoint.com/<sites-or-teams>/<team-name>"
$sUserName = "[email protected]"
$sFeatureGuid= "e995e28b-9ba8-4668-9933-cf5c146d7a9f"
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment