0

Is it possible to edit the items in an existing Quick Links web part using PowerShell PnP? I have seen posts about using the SharePoint workbench to get the JSON required to create a new web part. However, I want to add or remove items from an existing web part.

I tried using Get-PnPClientSideComponent to get the PropertiesJSON but this doesn't appear to include the full JSON that the workbench produces. So there isn't an items collection to work with (although I admit I might be missing something).

Any thoughts or help would be appreciated.

0

I started down the road of building a function that returns the complete json from the component received from Get-PnPClientSideComponent. The information is all there. It certainly can be improved upon but hope it helps.

function Get-PnpQuickLinksJson{

param(
  [parameter(Mandatory=$true)][OfficeDevPnP.Core.Pages.CanvasControl]$component
)

$json = "{
    'controlType': $($component.SpControlData.ControlType),
    'id': '$($component.SpControlData.Id)',
    'position': {
        'zoneIndex': $($component.SpControlData.Position.ZoneIndex),
        'sectionIndex': $($component.SpControlData.Position.SectionIndex),
        'controlIndex': $($component.SpControlData.Position.ControlIndex),
        'layoutIndex': $($component.SpControlData.Position.LayoutIndex)
    },
    'webPartId': '$($component.SpControlData.WebPartId)',

    'webPartData': {
        'id': '$($component.SpControlData.WebPartId)',
        'instanceId': '$($component.SpControlData.Id)',
        'title': 'Quick links',
        'description': '$($component.Description)',
        'serverProcessedContent': $($component.serverProcessedContent.ToString()),
        'dataVersion': '2.2',
        'properties': $($component.PropertiesJson)
    },
    'emphasis': {},
    'reservedHeight': 146,
    'reservedWidth': 744,
    'addedFromPersistedData': true
}";
#clean up characters for consistency
$json = $json.Replace("'",'"').Replace("`n", "").Replace("`t", "").Replace("`r", "");
$jsonObj = ConvertTo-Json $json;
return $jsonObj | ConvertFrom-Json;

}

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.