Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. $host.Runspace.ThreadOptions = "ReuseThread"
  2. function Enable-SPOFeature
  3. {
  4. param ($sCSOMPath,$sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid)
  5. try
  6. {
  7.  
  8. $sCSOMRuntimePath=$sCSOMPath + "Microsoft.SharePoint.Client.Runtime.dll"
  9. $sCSOMPath=$sCSOMPath + "Microsoft.SharePoint.Client.dll"
  10. Add-Type -Path $sCSOMPath
  11. Add-Type -Path $sCSOMRuntimePath
  12.  
  13. $spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl)
  14. $spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword)
  15. $spoCtx.Credentials = $spoCredentials
  16.  
  17. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  18. Write-Host "Enabling the Feature with GUID $sFeatureGuid !!" -ForegroundColor Green
  19. Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
  20.  
  21. $guiFeatureGuid = [System.Guid] $sFeatureGuid
  22. $web = $spoCtx.Web
  23.  
  24. try
  25. {
  26. $newWebFeature = $web.Features.Add($guiFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
  27. $newWebFeature.Retrieve("DisplayName")
  28. $spoCtx.Load($newWebFeature)
  29. $spoCtx.ExecuteQuery()
  30.  
  31.  
  32. if($newWebFeature.DefinitionId -ne $null){
  33. Write-Host $newWebFeature.DisplayName "Web scoped Feature activated"
  34. }
  35. }
  36. catch
  37. {
  38. Write-Host "Error in activating web scoped feature : $($_.Exception.Message)" -ForegroundColor Red
  39. }
  40.  
  41. pause
  42. }
  43. catch [System.Exception]
  44. {
  45. write-host -f red $_.Exception.ToString()
  46. pause
  47. }
  48. }
  49.  
  50.  
  51. $sSiteColUrl = "https://tenant.sharepoint.com/sites/ActivatesFeature/"
  52. $sUserName = "ActivatesFeature@tenant.onmicrosoft.com"
  53. $sFeatureGuid= "50b403aa-6541-2d2d-9394-54ed0c303b47"
  54.  
  55. #$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
  56. $sPassword=convertto-securestring "tenant" -asplaintext -force
  57. $sCSOMPath= "$PSScriptRoot_modules"#"<SPO_Path>"
  58.  
  59.  
  60. Enable-SPOFeature -sCSOMPath $sCSOMPath -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement