SharePoint Online: Disable Page Comments in Modern Sites using PowerShell

Requirement: Disable page comments in SharePoint Online Modern Sites and Communication sites.

sharepoint online disable page comments

How to Disable Page Comments in SharePoint Online?

Modern pages in SharePoint Online have a comments section at the bottom of each page for better collaboration. Comments are a great way to interact with others and get feedback on your content. However, there may be times when you want to disable comments for a page in SharePoint Online. In this article, we will show you how to do just that.

Option 1: Disable Comments at the tenant level

Page comments can be turned off at the tenant level by the below settings:

  1. Navigate to SharePoint Online Admin Center: 
  2. Click on Settings from the left navigation
  3. On the Settings page, select “Disable Comments on Site Pages.”
    sharepoint online disable comments
  4. Click OK to save your changes.

In the modern admin center, This is moved under:

  1. Settings >> Pages >> “Allow commenting on modern pages”
    sharepoint online turn off page comments

Wait for a while, and you’ll see the comments section is disabled from all pages in the tenant. You can also disable comments on modern pages at the tenant level using PowerShell.

SharePoint Online: Turn off comments by default

Use this PowerShell to disable page comments in SharePoint Online, Tenant-wide:


#Connect to SharePoint Online
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)

#Disable Comments on Site Pages at Tenant Level
Set-SPOTenant -CommentsOnSitePagesDisabled $True

Option 2: Disable Comments at the Page Level

Comments can be disabled at the page level. Here is how:

  1. Navigate to the SharePoint Online Site page >>  Edit the page.
  2. Turn off the comments by toggle the switch from ON to OFF position and publish the page.
    hide comments in sharepoint online modern page

This disables the comments section on the particular page.

Option 3: Disable Comments in SharePoint Online Pages using PowerShell

This PowerShell script disables the page comments for a given site:

#Load SharePoint CSOM Assemblies
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"
#Config Parameters
Try {
    #Get Credentials to connect
    $Cred= Get-Credential
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Get the Web
    $Web = $ctx.Web

    #Disable Comments in Site Pages
    $Web.CommentsOnSitePagesDisabled = $True
    Write-host -f Green "Page Comments has been disabled Successfully!"
Catch {
    write-host -f Red "Error:" $_.Exception.Message

Please note, disabling comments doesn’t delete existing comments on pages, it just hides them. Turning ON comments brings the comments back!

PnP PowerShell to Disable Comments on All Pages in a Library

$SiteURL= ""
$LibraryName = "SitePages"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get all Pages from the Library
$Pages = Get-PnPListItem -List $LibraryName | Where { $_.FileSystemObjectType -eq "File"}

#Loop through each Page 
ForEach($Page in $Pages)
    #Disable Comments
    Write-host "Disabling Comments on page:"$Page["FileLeafRef"]
    Set-PnPPage -Identity $Page["FileLeafRef"] -CommentsEnabled:$False


Disabling page comments in modern SharePoint Online sites is a simple and efficient way to prevent unwanted or inappropriate comments. By automating the process, administrators can quickly and easily disable comments for multiple sites, ensuring that the content and collaboration within their SharePoint environment remain secure and controlled. Whether you are disabling comments for one page, all pages in the sites, or tenant, this guide will help you quickly and easily disable page comments in SharePoint Online using PowerShell.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

6 thoughts on “SharePoint Online: Disable Page Comments in Modern Sites using PowerShell

  • Excellent PS1 code. Thank you.

    Line 15 for PNP has minor typo “Disabling Commnets” should be “Disabling Comments”

  • Better get all files instead of files and folders

    #PnP PowerShell to Disable Comments on All Pages in a Library
    $Pages = Get-PnPListItem -List $LibraryName | ? { $_.FileSystemObjectType -eq “File” }

  • Thanks for a great article. I have a script that iterates through all modern sites but I am having a devil of a time preventing the script from running if comments are already disabled. I know we can set the value using $Web.CommentsOnSitePagesDisabled = $True but how can i check the value first? I’ve tried using a variable(i.e. $prop = $Web.CommentsOnSitePagesDisabled but id doesn’t return true (if I know comments are disabled) or false (if I now comments are enabled). Is this possible? TIA 🙂
    ting the script
    $Web.CommentsOnSitePagesDisabled = $True

    Is it possible to identify if a site or page has comments enabled and then disabled it? I can’t seem to get the bool value of

  • I wish we could leave comments disabled at the tenant level and selectively enable on individual sites.


Leave a Reply

Your email address will not be published. Required fields are marked *