Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Load SharePoint Online Client Components SDK Module
- Import-Module 'C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll'
- # Set script constants
- $sitePagesFeatureIdString = 'B6917CB1-93A0-4B97-A84D-7CF49975D4EC'
- # Set up client context
- $userName = Read-Host "Username"
- $password = Read-Host "Password" -AsSecureString
- $siteUrl = Read-Host "Site Url"
- $webUrl = Read-Host "Server-Relative Web Url"
- $context = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userName, $password)
- $context.Credentials = $credentials
- # Get the list of existing features
- $web = $context.Site.OpenWeb($webUrl)
- $features = $web.Features
- $context.Load($features)
- $context.ExecuteQuery()
- # Verify that the Site Pages feature is present in the web
- if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -eq 0)
- {
- Write-Host "The Site Pages feature is already disabled in this web"
- return
- }
- # Remove the Site Pages feature from the web
- $features.Remove((new-object 'System.Guid' $sitePagesFeatureIdString), $false)
- $context.ExecuteQuery()
- # Verify that the Site Pages feature is no longer present in the Web
- $web = $context.Site.OpenWeb($webUrl)
- $features = $web.Features
- $context.Load($features)
- $context.ExecuteQuery()
- if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -eq 0)
- {
- Write-Host "The Site Pages feature has been successfully disabled"
- }
- else
- {
- throw "The Site Pages feature failed to be disabled"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement