Allow or prevent creation of site pages by end users

If you are a SharePoint admin, you can allow or prevent the creation of site pages by users. You can do this by changing settings in the SharePoint Admin center, or by using a Windows PowerShell script.

Note: Allowing or preventing creation of site pages at the site level can be done only by using a Windows PowerShell script.

Allow or prevent creation of site pages at the organization level in the SharePoint admin center

  1. Choose Admin centers and then SharePoint.

    Admin, SharePoint

  2. Choose Settings.

  3. Next to Site pages, select either Allow users to create site pages or Prevent users from creating site pages.

Allow or prevent creation of site pages at the site level with a Windows PowerShell script

Note: To run Windows PowerShell scripts, the minimum required execution policy for SharePoint Server 2016 is RemoteSigned, although the default policy for Windows PowerShell is Restricted. If the policy is left as Restricted, the SharePoint 2016 Management Shell will change the policy for Windows PowerShell to RemoteSigned. This means that you must select Run as administrator to start the SharePoint 2016 Management Shell with elevated administrative permission. This change will apply to all Windows PowerShell sessions. For more information, see ExecutionPolicy Enumeration. For additional information about scripts and execution policies, see about_scripts and about_Execution_Policies respectively.

To do this, you will use Client-side Object Model (CSOM). Before you use the script, verify that the following prerequisites are met:

  1. Verify that you meet the following minimum requirements:

    • You are a global administrator

    • You must read about_Execution_Policies.

    • In order for this script to work, you will need to install the SharePoint Online Client Components SDK.

    • The script will prompt you for a SiteUrl and WebUrl.

      The SiteUrl and WebUrl are comprised of the full URL which in this example is https://contoso.sharepoint.com/sites/marketing/northwindcompete

      For the SiteUrl you can use: https://contoso.sharepoint.com/sites/marketing

      and for the WebUrl you can use sites/marketing/northwindcompete.

  2. Copy the following code and paste it into a text editor, such as Notepad. For this article, we will name the script file, SitePagesOut.ps1.

    # Load SharePoint Online Client Components SDK Module
    Import-Module 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.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"
    }
    
  3. 1. Save the file, naming it SitePagesOut.ps1.

    Note: You can use a different file name, but you must save the file as an ANSI-encoded text file whose extension is .ps1.

  4. Change to the directory where you saved the file.

  5. At the Windows PowerShell command prompt, type the following command:

    ./SitePagesOut.ps1

To do this, you will use Client-side Object Model (CSOM). Before you use the script, verify that the following prerequisites are met:

  1. Verify that you meet the following minimum requirements:

    • You are a global administrator

    • You must read about_Execution_Policies.

    • In order for this script to work, you will need to install the SharePoint Online Client Components SDK.

    • The script will prompt you for a SiteUrl and WebUrl.

      The SiteUrl and WebUrl are comprised of the full URL which in this example is https://contoso.sharepoint.com/sites/marketing/northwindcompete

      For the SiteUrl you can use: https://contoso.sharepoint.com/sites/marketing

      and for the WebUrl you can use sites/marketing/northwindcompete.

  2. Copy the following code and paste it into a text editor, such as Notepad. For this article, we will name the script file, SitePagesIn.ps1.

    # Load SharePoint Online Client Components SDK Module
    Import-Module 'C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.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 not present in the web
    if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -gt 0)
    {
    	Write-Host "The Site Pages feature is already enabled in this web"
    	return
    }
    
    # Add the Site Pages feature back to the web
    $features.Add((new-object 'System.Guid' $sitePagesFeatureIdString), $false, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
    $context.ExecuteQuery()
    
    # Verify that the Site Pages feature is now present in the web
    $web = $context.Site.OpenWeb($webUrl)
    $features = $web.Features
    $context.Load($features)
    $context.ExecuteQuery()
    
    if(($features | ? { $_.DefinitionId -eq $sitePagesFeatureIdString }).Count -gt 0)
    {
    	Write-Host "The Site Pages feature has been successfully enabled"
    }
    else
    {
    	throw "The Site Pages feature failed to be enabled"
    }
    
  3. Save the file, naming it SitePagesIn.ps1.

    Note: You can use a different file name, but you must save the file as an ANSI-encoded text file whose extension is .ps1.

  4. Change to the directory where you saved the file.

  5. At the Windows PowerShell command prompt, type the following command:

    ./SitePagesIn.ps1

    For additional information about Windows PowerShell, see Using Windows PowerShell.

Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×