SOLVED

Adding People to the People Web Part Programmatically (using PowerShell maybe?)

%3CLINGO-SUB%20id%3D%22lingo-sub-110559%22%20slang%3D%22en-US%22%3EAdding%20People%20to%20the%20People%20Web%20Part%20Programmatically%20(using%20PowerShell%20maybe%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110559%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20doesn't%20seem%20to%20be%20any%20documentation%20relating%20to%20the%20modern%20web%20part%20components.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20can%20add%20a%20modern%20web%20part%20component%20to%20the%20page%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EAdd-PnPClientSideWebPart%20-Page%20%24home%20-DefaultWebPartType%20People%3C%2FPRE%3E%3CP%3EBut%20I%20cannot%20work%20out%20how%20to%20actually%20add%20people%20to%20it.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20thoughts%20greatfully%20received%20(although%20I%20don't%20hold%20out%20much%20hope%20--%20it's%20very%20quiet%20around%20here).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-110559%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-111030%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20People%20to%20the%20People%20Web%20Part%20Programmatically%20(using%20PowerShell%20maybe%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-111030%22%20slang%3D%22en-US%22%3E%3CP%3EWoot!%20%26nbsp%3BFinally%20managed%20it.%20%26nbsp%3BIt's%20just%20so%20frustrating%20how%20simple%20it%20looks%20when%20you%20finally%20work%20it%20out.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24homePage%20%3D%20Get-PnPClientSidePage%20-Identity%20%22Home%22%0A%24peoplePart%20%3D%20%24homePage.Controls%20%7C%20%3F%20%7B%24_.Title%20-eq%20%22People%22%7D%0A%24peoplePart.PropertiesJson%20%3D%20'%7B%22layout%22%3A1%2C%22persons%22%3A%5B%7B%22id%22%3A%22i%3A0%23.f%7Cmembership%7Cdparkinson%40yourtenant.com%22%2C%22role%22%3A%22%22%7D%5D%2C%22title%22%3A%22Account%20Team%22%7D'%0A%24homePage.Save()%3C%2FPRE%3E%3CP%3ENote%3A%20this%20assumes%20only%20a%20single%20control%20on%20the%20page%20called%20%22People%22%3B%20and%20this%20also%20changes%20the%20title.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20actually%20set%20the%20title%20by%20just%20using%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24peoplePart.Title%20%3D%20%22My%20New%20Title%22%3CBR%20%2F%3E%24homePage.Save()%3C%2FPRE%3E%3CP%3EBut%20the%20PropertiesJson%20already%20includes%20it.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10723%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%26nbsp%3Byour%20tip%20was%20very%20helpful%20in%20pointing%20the%20right%20direction.%20%26nbsp%3BI%20always%20forget%20about%20Get-PnPProvisioning%20for%20looking%20at%20specific%20items.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EKind%20regards%2C%3C%2FP%3E%3CP%3ED.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-110879%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20People%20to%20the%20People%20Web%20Part%20Programmatically%20(using%20PowerShell%20maybe%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110879%22%20slang%3D%22en-US%22%3E%3CP%3EInteresting%20that%20it's%20only%20adding%20the%20JsonControlData%20field%20which%20is%20what%20I've%20be%20trying%20to%20do%20via%20PowerShell.%20I'll%20give%20it%20another%20go%20with%20that%20before%20giving%20up.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-110613%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20People%20to%20the%20People%20Web%20Part%20Programmatically%20(using%20PowerShell%20maybe%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-110613%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F53811%22%20target%3D%22_blank%22%3E%40Darren%20Parkinson%3C%2FA%3E%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20ran%20Get-PnPProvisioning%20Template%20before%20adding%20a%20people%20web%20part%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20I%20added%20a%20people%20web%20part%20and%20then%20ran%20Get-PnPProvisioningTemplate%20again%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20difference%20is%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%3CCANVASCONTROL%20webparttype%3D%22People%22%20jsoncontroldata%3D%22%7B%26amp%3Bquot%3Blayout%26amp%3Bquot%3B%3A1%2C%26amp%3Bquot%3Bpersons%26amp%3Bquot%3B%3A%5B%7B%26amp%3Bquot%3Bid%26amp%3Bquot%3B%3A%26amp%3Bquot%3Bi%3A0%23.f%7Cmembership%7Cpieter%40mytenant.onmicrosoft.com%26amp%3Bquot%3B%2C%26amp%3Bquot%3Brole%26amp%3Bquot%3B%3A%26amp%3Bquot%3B%26amp%3Bquot%3B%7D%5D%7D%22%20controlid%3D%227f718435-ee4d-431c-bdbf-9c4ff326f46e%22%20column%3D%221%22%3E%3C%2FCANVASCONTROL%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20the%26nbsp%3BAdd-PnPClientSideWebPart%20I%20couldn't%20find%20anything%20to%20add%20the%20data%2C%20but%20you%20could%20create%20a%20template%20whcih%20just%20includes%20the%26nbsp%3B%20above%20webpart%20details%20and%20then%20add%20the%20web%20part%20with%20Apply-ProvisioningTemplate.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-886537%22%20slang%3D%22en-US%22%3ERe%3A%20Adding%20People%20to%20the%20People%20Web%20Part%20Programmatically%20(using%20PowerShell%20maybe%3F)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-886537%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F53811%22%20target%3D%22_blank%22%3E%40Darren%20Parkinson%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F10723%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20a%20lot%20for%20this%20information.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20put%202%20variables%20in%20this%20code.%20I%20can't%20find%20the%20solution.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESomething%20like%20this%20(First%20time%20I%20use%20Json%20%3A)%3C%2Fimg%3E%20)%20%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24userMail%20%3D%20%22dparkinson%40yourtenant.com%22%0A%24title%20%3D%20%22Account%20Team%22%0A%24homePage%20%3D%20Get-PnPClientSidePage%20-Identity%20%22Home%22%0A%24peoplePart%20%3D%20%24homePage.Controls%20%7C%20%3F%20%7B%24_.Title%20-eq%20%22People%22%7D%0A%24peoplePart.PropertiesJson%20%3D%20'%7B%22layout%22%3A1%2C%22persons%22%3A%5B%7B%22id%22%3A%22i%3A0%23.f%7Cmembership%7C%24userMail%22%2C%22role%22%3A%22%22%7D%5D%2C%22title%22%3A%24title%7D'%0A%24homePage.Save()%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20this%20but%20it%20doesn't%20work%20%3A%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24user%20%3D%20%22dparkinson%40yourtenant.com%22%0A%24title%20%3D%20%22Account%20Team%22%0A%24homePage%20%3D%20Get-PnPClientSidePage%20-Identity%20%22%24PageName%22%0A%24peoplePart%20%3D%20%24homePage.Controls%20%7C%20%3F%20%7B%24_.Title%20-eq%20%22People%22%7D%0A%24peoplePart.PropertiesJson%20%3D%20'%7B%7B%22layout%22%3A1%2C%22persons%22%3A%5B%7B%22id%22%3A%22i%3A0%23.f%7Cmembership%7C%7B0%7D%22%2C%22role%22%3A%22%22%7D%5D%2C%22title%22%3A%22%7B1%7D%22%7D%7D'%20-f%20%24user%2C%24title%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20idea%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor

There doesn't seem to be any documentation relating to the modern web part components.

 

I can add a modern web part component to the page like this:

 

Add-PnPClientSideWebPart -Page $home -DefaultWebPartType People

But I cannot work out how to actually add people to it.

 

Any thoughts greatfully received (although I don't hold out much hope -- it's very quiet around here).

 

6 Replies
best response confirmed by Juan Carlos González Martín (MVP)
Solution

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="{&quot;layout&quot;:1,&quot;persons&quot;:[{&quot;id&quot;:&quot;i:0#.f|membership|pieter@mytenant.onmicrosoft.com&quot;,&quot;role&quot;:&quot;&quot;}]}" 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.

 

 

 

 

Interesting that it's only adding the JsonControlData field which is what I've be trying to do via PowerShell. I'll give it another go with that before giving up.

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.

 

@Darren Parkinson 

@Pieter Veenstra 

Thanks a lot for this information.

 

I would like to put 2 variables in this code. I can't find the solution.

 

Something like this (First time I use Json :) ) :

 

$userMail = "dparkinson@yourtenant.com"
$title = "Account Team"
$homePage = Get-PnPClientSidePage -Identity "Home"
$peoplePart = $homePage.Controls | ? {$_.Title -eq "People"}
$peoplePart.PropertiesJson = '{"layout":1,"persons":[{"id":"i:0#.f|membership|$userMail","role":""}],"title":$title}'
$homePage.Save()

 

 

I tried this but it doesn't work :

$user = "dparkinson@yourtenant.com"
$title = "Account Team"
$homePage = Get-PnPClientSidePage -Identity "$PageName"
$peoplePart = $homePage.Controls | ? {$_.Title -eq "People"}
$peoplePart.PropertiesJson = '{{"layout":1,"persons":[{"id":"i:0#.f|membership|{0}","role":""}],"title":"{1}"}}' -f $user,$title

 

Any idea ?

@Jeremy GOUPIL 

Worked for me:

 

$userMail = "user@tenant.com"
$title = "Test User"
$homePage = Get-PnPClientSidePage -Identity "Home"
$peoplePart = $homePage.Controls | ? {$_.Title -eq "People"}
$peoplePart.PropertiesJson = '{"layout":1,"persons":[{"id":"i:0#.f|membership|$userMail","role":""}],"title":"$title"}'
$homePage.Save()

 

Do you have an idea how to add multiple users to the webpart?

 

Thanks. 

@Andrei Rachita 

$SiteAdmin1 ="someuser@domain.com"
$SiteAdmin2 ="someuser2@domain.com"

$homePage = Get-PnPClientSidePage -Identity "Home"
$peoplePart = $homePage.Controls | ? {$_.Title -eq "People"}
$peopleName='[{"id":"i:0#.f|membership|'+$SiteAdmin1+'"},{"id":"i:0#.f|membership|'+$SiteAdmin2+'"}]'
$jsonp='{"title":"Site Contact","layout":1,"persons":'+$peopleName+'}'
$peoplePart.PropertiesJson = $jsonp
$homePage.Save()
$homePage.Publish()

 

Kind regards

Vikram Rai (Sopra Steria, Norway)