How do I get my instanceId to put a Property module on my Sharepoint page?

Hello

Here you can find my current code to upload to my sharepoint page it’s property ‘SME’.

When I manually add the instanceId it works, but I cannot find a way to get it automatically from my page name. Does someone know how to do this?

Thanks!

Louis

# Connect to SharePoint site
Connect-PnPOnline -Url "https://xxxxx.sharepoint.com/sites/KBITAM" -UseWebLogin

$pageURL = "Vendor-1.aspx"
$page = Get-PnPPage -Identity "Vendor-1.aspx"

$instanceId = ??????

$jsonProps = @"
{
   "position": {
     "zoneIndex": 1,
     "sectionIndex": 1,
     "controlIndex": 1,
     "layoutIndex": 1
   },
   "webPartData": {
     "id": "36da5d31-e6d4-4648-b669-58c5c98c7060",
     "instanceId": "$instanceId",
     "title": "SME",
     "description": "Subject Matter Expert",
     "audiences": [],
     "serverProcessedContent": {
       "htmlStrings": {},
       "searchablePlainTexts": {},
       "imageSources": {},
       "links": {}
     },
     "dataVersion": "1.0",
     "properties": {
       "title": "SME",
       "selectedFieldIds": [],
       "availableFields": [],
       "minimumLayoutWidth": 2
     },
     "containsDynamicDataSource": false
   },
   "controlType": 3,
   "id": "9c797b9c-dc44-4101-b9f5-938170cd4d44",
   "webPartId": "$instanceId",
   "emphasis": {},
   "zoneGroupMetadata": {
     "type": 0
   },
   "reservedHeight": 326,
   "reservedWidth": 744,
   "addedFromPersistedData": true
 }
"@

Add-PnPPageWebPart -Page $page -DefaultWebPartType List -WebPartProperties $jsonProps -Section 2 -Column 1
$page.Publish()