Sharepoint powershell for viewing all comments in pages, on a sharepoint site
I got referred here from this query.
https://answers.microsoft.com/en-us/msoffice/forum/all/collecting-a-list-of-all-comments-made-in-the/e1ab0dbf-f9fe-43e2-a014-af6abdcaf2e8?rtAction=1738593869018
I've never used PowerShell before, and so will need to figure out how to do this. but before I spend time on this, is this a once off solution showing comments at the point of running it, or is it updating and once this is done can I refer back to it?
For reference, what I'm trying to do is collect all comments on a SharePoint site from the various pages (there are approx 40) in an automatically updating log.
Not every user @'s the correct person or admin so that updates/changes can be reviewed and made. I would like one central 'area' or 'log' that can collect the comments, so that the people in charge of updating the pages can just monitor the one 'log'.
The code that was given in the link is this:
You can use the REST API to call the /Comments
endpoint:
/_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
} else {
Write-host "No comments where found on this page."
}
Write-host ------------------------------ `n`n`n`n`n
}