HI @anna
Please try the REST API to call the endpoint:/Comments
/_api/web/lists/GetByTitle('Site Pages')/GetItemById(x)/Comments
Here is the PowerShell code:
$SiteURL = "https://yourtenant.sharepoint.com/sites/TargetSiteCollection"
Connect-PnPOnline $SiteURL -UseWebLogin
$ListName= "Site Pages"
$allSitePages = Get-PnPListItem -List $ListName
foreach ($sitePage in $allSitePages)
{
Write-host ------------------------------
$pageID = $sitePage["ID"]
Write-host 'Site Page' $pageID ':' $sitePage["Title"]
$RestMethodURL = $SiteURL+"/_api/web/lists/GetByTitle('$ListName')/GetItemById('$pageID')/Comments"
$ListOfComments = Invoke-PnPSPRestMethod -Url $RestMethodURL
if ($ListOfComments.value)
{
# Comments exsist!
Write-host $ListOfComments.value.Count comments found:
$ListOfComments.value.text
} else {
Write-host "No comments where found on this page."
}
Write-host ------------------------------
}
Here is result:
Here is link for your reference:
https://veronicageek.com/2019/get-likes-and-comments-count-on-pages/
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards
Cheng Feng