How can I get all the web part data json using PnP Powershell?

Viewed 21

I am tryin to retrieve the json properties of a quick links web part that you can see through the workbench option "Web part data". However when getting the PropertiesJson value it only returns a fragment of that json shown below:

Web part data

Currently this is the script I have made to pull this data:

$SiteUrl = Read-Host -Prompt "Input site url"

Connect-PnPOnline $SiteUrl -Interactive

function Process-Pages
{
    param (
        [string]$FolderName
    )

    if($FolderName -ne $null -and $FolderName -ne "")
    {
        $FolderName = $FolderName + "/"
    }

    # Get files/folders in library
    $fileDir = $FolderName + "SitePages"
    $fileDir
    $items = Get-PnPFolderItem -FolderSiteRelativeUrl $fileDir

    foreach ($item in $items)
    {
        $itemType = $($item.TypedObject -replace "Microsoft.SharePoint.Client.","")
        $itemName = $item.Name
    
        if($itemType -eq "File")
        {
            # Write-Host "Processing: " $itemName -ForegroundColor Green
        
            $page = Get-PnPPage -identity $itemName
            $webparts = $page.Controls | ? {$_.Title -eq "Quick links"}
        
            foreach($webpart in $webparts)
            {
                Write-Host "Processing: " $itemName -ForegroundColor Green
                Write-Host "Starting to process json properties" -ForegroundColor Blue
            
                $json = $webpart.PropertiesJson
                Write-Host $json
            }
        }
        else
        {
            Write-Host "Diving into folder: " $itemName -ForegroundColor Yellow
        
            Process-Pages -FolderName $itemName
        }
    }
}

Process-Pages

I have tried using commands such as Get-PnPPageComponent, Get-PnPClientSideComponent, Get-PnPWebPart and Get-PnPWebPartProperty and none of these have gotten me what I am looking for.

What I am trying to achieve essentially is to update the quick links web part so that I can update a link on all pages of my site automatically with a script. For example if I wanted to rename all links with the title "Google" on my site (within a quick links web part) to "Alphabet". Another scenario could be to update the url for all links that currently point to "https://hotmail.com" to "https://outlook.com" and finally update all links with the title "Outlook" change the url associated to it regardless of its current url to "https://outlook.com".

Could I get some assistance with firstly getting back the full json as shown in the screenshot provided? Also any feedback on if what I am trying to do is achievable (even if its not through PnP) would be greatly appreciated.

0 Answers
Related