Disable SPO Modern Comments with PowerShell automation
Step by step demo how to Disable SPO Modern Comments with PowerShell automation. Useful for scenario where Communication site or Publishing portal has well moderated text and goal is to avoid user comments added by anyone on page footer. NOTE – Comments are DELETED when the disable executes. Attempts to re-enable comments again will show a blank thread (prior text comments not visible).
Cheers

VIDEO
CODE
# Load PnP PowerShell Module
#Install-Module "PnP.PowerShell" -MaxVersion 1.13 -Scope CurrentUser
Import-Module "PnP.PowerShell"
# Register the app for interactive login with Azure Application Registration
Register-PnPEntraIDAppForInteractiveLogin -Tenant "spjeffdev.onmicrosoft.com" -ApplicationName "PnP Shell"
# Target SharePoint site URL
$url = "https://spjeffdev.sharepoint.com/sites/Communication"
$clientId = "a31e1734-a19e-43d4-9b37-88cf71f67610" # Replace with your registered app's client ID
# Connect to SharePoint Online site
Connect-PnPOnline -Url $url -Interactive -ClientId $clientId
# Get the current web to display Title and URL
Get-PnPWeb
# Disable modern comments for each Site Pages library
$pages = Get-PnPClientSidePage | Where-Object { $_.Name -like "*.aspx" }
$pages | Format-Table Name, CommentsEnabled -AutoSize
foreach ($page in $pages) {
Write-Host "Disabling comments on page: $($page.Name)"
Set-PnPClientSidePage -Identity $page.Name -CommentsEnabled:$false
}SCREENSHOT


REFERENCES
