Export all liked-by information of all modern pages in SharePoint site

Here is a straightforward PowerShell script that uses PnP PowerShell to export a list of all Pages from the Site Pages library of a SharePoint site, including the users who liked them.

In the fast-paced world of data management and automation, the ability to export data efficiently is a skill highly required by professionals across various fields. Fortunately, PowerShell scripts offer a powerful solution to streamline this process, allowing users to extract and manipulate data with ease.

Here’s a simple PowerShell script that assists in exporting the list of all Pages from Site Pages library from SharePoint Site including the users who liked them by utilising PnP PowerShell.

PnP PowerShell version used:2.4.71-nightly
Write-Host "Execution Started..."
$siteurl = "https://<tenant_name>.sharepoint.com/sites/<site_name>"
Connect-PnPOnline $siteurl -Interactive
$files = Get-PnPFileInFolder -Identity "SitePages"
Write-Host "Total files found: "$files.length
if ($files.length -gt 0) {
    Write-Host "Export Started..."
    $results = @()
    foreach ($file in $files) {
        Write-Host $file.Name
        $likes = Get-PnPPageLikedByInformation -Identity $file.Name
        if ($likes.length -gt 0) {
            foreach ($like in $likes) {
                $results += [pscustomobject][ordered]@{
                    Name  = $file.Name
                    Title = $file.Title
                    UserLiked = $like.Name
                    UserMail = $like.Mail
                }
            }
        }else{
            $results += [pscustomobject][ordered]@{
                Name  = $file.Name
                Title = $file.Title
                UserLiked = ""
                UserMail = ""
            }
        }
    }
   
    $results | Export-Csv -Path "allpagewithlikes.csv" -NoTypeInformation
    Write-Host "Export Completed."
}
Write-Host "Execution Ended."

The above script iterates to all the modern pages from the Site Pages library and retrieve the liked by information by using GetPnPPageLikedByInformation command. Then it exports in to the csv file in current running path.

 

Shantha Kumar
Shantha Kumar
Articles: 296