Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $host.Runspace.ThreadOptions = "ReuseThread"
- function Enable-SPOFeature
- {
- param ($sCSOMPath,$sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
- try
- {
- $sCSOMRuntimePath=$sCSOMPath + "Microsoft.SharePoint.Client.Runtime.dll"
- $sCSOMPath=$sCSOMPath + "Microsoft.SharePoint.Client.dll"
- Add-Type -Path $sCSOMPath
- Add-Type -Path $sCSOMRuntimePath
- $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
- $web = $spoCtx.Web
- try
- {
- $newWebFeature = $web.Features.Add($guiFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
- $newWebFeature.Retrieve("DisplayName")
- $spoCtx.Load($newWebFeature)
- $spoCtx.ExecuteQuery()
- if($newWebFeature.DefinitionId -ne $null){
- Write-Host $newWebFeature.DisplayName "Web scoped Feature activated"
- }
- }
- catch
- {
- Write-Host "Error in activating web scoped feature : $($_.Exception.Message)" -ForegroundColor Red
- }
- pause
- }
- catch [System.Exception]
- {
- write-host -f red $_.Exception.ToString()
- pause
- }
- }
- $sSiteColUrl = "https://tenant.sharepoint.com/sites/ActivatesFeature/"
- $sUserName = "ActivatesFeature@tenant.onmicrosoft.com"
- $sFeatureGuid= "50b403aa-6541-2d2d-9394-54ed0c303b47"
- #$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
- $sPassword=convertto-securestring "tenant" -asplaintext -force
- $sCSOMPath= "$PSScriptRoot_modules"#"<SPO_Path>"
- Enable-SPOFeature -sCSOMPath $sCSOMPath -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement