Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. # Load SharePoint Online Client Components SDK Module
  2. Import-Module 'C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll'
  3.  
  4. # Set script constants
  5. $sitePagesFeatureIdString = 'B6917CB1-93A0-4B97-A84D-7CF49975D4EC'
  6.  
  7. # Set up client context
  8. $userName = Read-Host "Username"
  9. $password = Read-Host "Password" -AsSecureString
  10. $siteUrl = Read-Host "Site Url"
  11. $webUrl = Read-Host "Server-Relative Web Url"
  12. $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
  13. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
  14. $context.Credentials = $credentials
  15.  
  16. # Get the list of existing features
  17. $web = $context.Site.OpenWeb($webUrl)
  18. $features = $web.Features
  19. $context.Load($features)
  20. $context.ExecuteQuery()
  21.  
  22. # Verify that the Site Pages feature is present in the web
  23. if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -eq 0)
  24. {
  25. Write-Host "The Site Pages feature is already disabled in this web"
  26. return
  27. }
  28.  
  29. # Remove the Site Pages feature from the web
  30. $features.Remove((new-object 'System.Guid' $sitePagesFeatureIdString), $false)
  31. $context.ExecuteQuery()
  32.  
  33. # Verify that the Site Pages feature is no longer present in the Web
  34. $web = $context.Site.OpenWeb($webUrl)
  35. $features = $web.Features
  36. $context.Load($features)
  37. $context.ExecuteQuery()
  38. if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -eq 0)
  39. {
  40. Write-Host "The Site Pages feature has been successfully disabled"
  41. }
  42. else
  43. {
  44. throw "The Site Pages feature failed to be disabled"
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement