Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BeniFreitag/4d77293503c5671a521340f5a3d92122 to your computer and use it in GitHub Desktop.
Save BeniFreitag/4d77293503c5671a521340f5a3d92122 to your computer and use it in GitHub Desktop.
Get-SPSite -Limit ALL | ForEach-Object {
$siteCollection = $PSItem
$siteCollection.AllWebs | ForEach-Object {
$web = $PSItem
$sitePages = $web.Lists["Site Pages"]
if ($sitePages) {
$sitePages.Items | Where-Object { $_["_CommentCount"] -ge 1 } | ForEach-Object {
$sitePage = $PSItem
$pageUrl = $web.Url + "/" + $sitePage.Url
$sitePageAuthor = (New-Object Microsoft.SharePoint.SPFieldLookupValue $sitePage["Author"]).LookupValue
$comments = Invoke-RestMethod -Method Get -Uri "$($web.Url)/_api/web/Lists('$($sitePages.ID)')/GetItemById($($sitePage.ID))/Comments?`$expand=replies&`$top=4000" -UseDefaultCredentials -Headers @{accept = 'application/json' }
$comments.value | ForEach-Object {
$comment = $PSItem
Write-Output ([PSCustomObject]@{
PageUrl = $pageUrl
PageAuthor = $sitePageAuthor
PageCommentCount = $sitePage["_CommentCount"]
PageTitle = $sitePage.Title
CommentId = $comment.id
CommentCreated = [DateTime]$comment.createdDate
IsReply = $comment.isReply
CommentAuthor = $comment.author.name
ReplyCount = $comment.replyCount
CommentText = $comment.text
})
$comment.replies | ForEach-Object {
$reply = $PSItem
Write-Output ([PSCustomObject]@{
PageUrl = $pageUrl
PageAuthor = $sitePageAuthor
PageCommentCount = $sitePage["_CommentCount"]
PageTitle = $sitePage.Title
CommentId = $reply.id
CommentCreated = [DateTime]$reply.createdDate
IsReply = $reply.isReply
CommentAuthor = $reply.author.name
ReplyCount = $null
CommentText = $reply.text
})
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment