How can I export the comments left by visitor in a SharePoint Site?

anna 0 Reputation points
2023-09-14T08:24:44.8933333+00:00

Hi expert,

How can I export the comments added by visitors in a SharePoint Site? Since there are many comments, I need to export them. Thank you.image

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2023-09-15T02:16:12.5733333+00:00

    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:

    User's image

    Here is link for your reference:

    https://veronicageek.com/2019/get-likes-and-comments-count-on-pages/

    https://sharepoint.stackexchange.com/questions/302014/get-all-comments-from-modern-site-pages-in-sharepoint-online


    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


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.