Forum Discussion
Adding People to the People Web Part Programmatically (using PowerShell maybe?)
- Sep 26, 2017
Hi Darren Parkinson,
I ran Get-PnPProvisioning Template before adding a people web part
Then I added a people web part and then ran Get-PnPProvisioningTemplate again
The difference is :
<pnp:CanvasControl WebPartType="People" JsonControlData="{"layout":1,"persons":[{"id":"i:0#.f|membership|pieter@mytenant.onmicrosoft.com","role":""}]}" ControlId="7f718435-ee4d-431c-bdbf-9c4ff326f46e" Column="1" />On the Add-PnPClientSideWebPart I couldn't find anything to add the data, but you could create a template whcih just includes the above webpart details and then add the web part with Apply-ProvisioningTemplate.
Hi Darren Parkinson,
I ran Get-PnPProvisioning Template before adding a people web part
Then I added a people web part and then ran Get-PnPProvisioningTemplate again
The difference is :
<pnp:CanvasControl WebPartType="People" JsonControlData="{"layout":1,"persons":[{"id":"i:0#.f|membership|pieter@mytenant.onmicrosoft.com","role":""}]}" ControlId="7f718435-ee4d-431c-bdbf-9c4ff326f46e" Column="1" />
On the Add-PnPClientSideWebPart I couldn't find anything to add the data, but you could create a template whcih just includes the above webpart details and then add the web part with Apply-ProvisioningTemplate.
Woot! Finally managed it. It's just so frustrating how simple it looks when you finally work it out.
$homePage = Get-PnPClientSidePage -Identity "Home"
$peoplePart = $homePage.Controls | ? {$_.Title -eq "People"}
$peoplePart.PropertiesJson = '{"layout":1,"persons":[{"id":"i:0#.f|membership|dparkinson@yourtenant.com","role":""}],"title":"Account Team"}'
$homePage.Save()Note: this assumes only a single control on the page called "People"; and this also changes the title.
You can actually set the title by just using:
$peoplePart.Title = "My New Title"
$homePage.Save()
But the PropertiesJson already includes it.
Thanks Pieter Veenstra your tip was very helpful in pointing the right direction. I always forget about Get-PnPProvisioning for looking at specific items.
Kind regards,
D.