PowerShell script to change the People web part properties on a modern SharePoint site

Technology Specialist
October 14, 2018
Rate this article
[Total: 0    Average: 0/5]

In this article, let us see how to change the site contact properties on a People web part for the multiple site since we can’t go and change it manually every time if we need to update the properties for the multiple site collection. To avoid this manual activity, we can use PowerShell script

The below script is used to get the site owner information from the excel file and retrieve the web part present on the site’s home page and update the propertyJSON for the people web part with the values provided in the excel file.


 Write-Output -msg "Start : Module loading Process"
 $modulePath = "C:\Program Files\SharePoint Online Management Shell\SharePointPnPPowerShellOnline"
         import-module ($modulePath + "\SharePointPnPPowerShellOnline.psd1")
         Add-Type -Path ($modulePath + "\SharePointPnP.PowerShell.Online.Commands.dll")
         Add-Type -Path ($modulePath + "\Microsoft.SharePoint.Client.dll")
         Add-Type -Path ($modulePath + "\Microsoft.SharePoint.Client.Runtime.dll")
         Add-Type -Path ($modulePath + "\Microsoft.Online.SharePoint.Client.Tenant.dll")
 Write-Output -msg "End : Module loading Process"
 $pwd ="xxxxxxx"
 #Get the input sites from Excel File
 $objExcel = New-Object -ComObject Excel.Application
 $objExcel.Visible = $false
 $objExcel.UserControl= $True
 [threading.thread]::CurrentThread.CurrentCulture = 'en-US'
 $WorkBook = $objExcel.Workbooks.Open($inputFilePath)
 $WorkSheet = $WorkBook.sheets.item("Sheet1")
 $rowMax = ($WorkSheet.UsedRange.Rows).count
 for ($i=2; $i -le $rowMax; $i++)
     $encpassword = convertto-securestring -String $pwd -AsPlainText -Force
     $cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $UserName, $encpassword
 # Connect Site
     Connect-PnPOnline -Url $createdSiteURL -Credentials $cred
     Write-Output $createdSiteURL
 #Get the Webparts available in the home page and update the propertiesjson for People Webpart
     $webpart=Get-PnPClientSideComponent -Page Home 
     foreach($w in $webpart)
       if($w.Title -eq "People")
         $jsonp='{"title":"Site Contact","layout":1,"persons":'+$peopleName+'}'
         Set-PnPClientSideWebPart -Page "Home" -Identity $peoplewbInstanceId -PropertiesJson $jsonp
         Set-PnPClientSidePage -Identity "Home" -Publish
      Write-Output $_.Exception.Message



Hope this helps!

Category : SharePoint, SPFx

Author Info

Technology Specialist
Rate this article
[Total: 0    Average: 0/5]
Having 6 years of experience in design and development of SharePoint applications, Mani has expertise in developing applications using Office 365, SharePoint 2013 & 2010, SPFX, SP Designer Workflows, Visual ...read more

Leave a comment