Modern pages

In SharePoint modern pages you have an option to enable or disable comments when editing a page. If you want to disable comments on a new Site Page, you have to publish the Page first and then Edit it again for the Comments section and button to appear.

Starting from CSOM package 16.1.6518.1200 you can disable or enable comments on ALL pages in a site collection using Powershell. The property is called CommentsOnSitePagesDisabled and the setting will work on each page right from the start.
The CommentsOnSitePagesDisabled also gives the administrator more control over users' editions. If the property is set to $true, the users with Member Group privileges will not see the option to turn the comments off or on. 


If you haven't used them yet, use NuGet Gallery to download the latest SharePoint Client Object Model libraries


First, load the necessary libraries. Below you can see an example using the default paths:
# Paths to SDK. Please verify location on your computer.
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Create SharePoint client context and verify the connection. Make sure to replace $url, $username and $adminpassword with correct values. $AdminPassword has to be of SecureString type:
$ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username$AdminPassword)
  catch [Net.WebException]
      Write-Host $Url " failed to connect to the site" $_.Exception.Message.ToString() -ForegroundColor Red

Load the web object:
$web $ctx.Web 

Change the CommentsOnSitePagesDisabled property to $true and update the $web object:
$web.CommentsOnSitePagesDisabled = $true



When the CommentsOnSitePagesDisabled property is set to $true, users with editor rights will not see the comments section at all when editing the page. The setting applies to all pages on a given site, the old and the ones created in the future.


See Also

How to enable the setting on a single page or globally using GUI