Contents

Get likes and comments count on SharePoint pages using PowerShell

 

Today, we’re going to play a bit with SharePoint Online pages, and try to get the number of Likes & Comments we have for each page within a Site Collection. Without further due, let’s get started!

Get likes and comments count for all pages on a Site

It might be useful to get get a report as to how your pages are performing, and you can get this with PowerShell. Blow is a full script for your comvenience!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#Connect to SPO site
Connect-PnPOnline -Url https://<TENANT-NAME>.sharepoint.com/sites/<YOUR-SITE>

#Store pages into a variable
$sitePagesGallery = Get-PnPList -Identity "Site Pages"

#Get the pages details 
$logFile = "C:\users\$env:USERNAME\Desktop\LikesAndComments.csv"
$results = @()

foreach ($item in $sitePagesGallery) {
    $allPages = Get-PnPListItem -List $sitePagesGallery -Fields "FileLeafRef", "Title", "ID", "FileRef", "_CommentCount", "_LikeCount"
    
    #Choose the properties to export
    foreach ($page in $allPages) {
        $results += New-Object -TypeName psobject -Property @{
            Title         = $page["Title"]
            ID            = $page.ID
            FullPath      = $page["FileRef"]
            NumOfComments = $page["_CommentCount"]
            NumOfLikes    = $page["_LikeCount"]        
        }
    }
}
$results | Export-Csv -Path $logFile -NoTypeInformation

 

Et voilà!

/images/powershell-screenshots/get-likes-and-comments.png