Introduction 

In the realm of SharePoint Online, the integration of dynamic elements like Bing Maps enhances the user experience and provides a visually interactive way to present location-based data. However, SharePoint administrators often face challenges in updating these elements seamlessly. One effective solution is using PowerShell, specifically the Patterns and Practices (PnP) PowerShell module. In this blog post, we’ll explore how to update a Bing Maps web part on a SharePoint site using PnP PowerShell. 

What is PnP PowerShell? 

PnP PowerShell is a powerful set of commands that simplifies various administrative and development tasks in SharePoint Online. It extends the capabilities of the native SharePoint Online Management Shell, providing more flexibility and functionality for managing SharePoint Online environments. 

Updating Bing Maps in SharePoint 

Scenario 

Consider a scenario where we have a SharePoint page with a Bing Maps web part. We need to update the map’s location to display a new area, in this case, “Meir, 2000 Antwerp, Belgium.” 

Prerequisites 

Before proceeding, ensure you have: 

  • Access to the SharePoint Online site. 
  • PnP PowerShell module installed. 
  • Necessary permissions to update the SharePoint page. 

Step-by-Step Guide 

  • Connect to SharePoint Online 

Start by connecting to your SharePoint Online site using the Connect-PnPOnline cmdlet. It’s essential to authenticate with the necessary permissions to make changes. 

$SiteURL = "https://contoso.sharepoint.com" 
Connect-PnPOnline -Url $SiteURL -Interactive 
  • Retrieve the Page 

Fetch the specific page where the Bing Maps web part resides.

$PageName = "Home.aspx" 
$Page = Get-PnPPage -Identity $PageName 
  • Locate the Bing Maps Web Part 

Identify the Bing Maps web part using its title. 
 

$WebPartTitle = "Bing Maps" 
$webPart = $Page.Controls | Where-Object {$_.Title -eq $WebPartTitle} 
  • Prepare the JSON Configuration 

Define the new map configuration in JSON format. This includes the coordinates, pushpin information, zoom level, and map type. 

$jsonProperty = '{"pushPins":[{"location": ... "altitudeReference":-1}}' 

Full json code:  

$jsonProperty = '{"pushPins":[{"location":{"latitude":51.218780,"longitude":4.405590,"altitude":0,"altitudeReference":-1},"defaultTitle":"Meir","defaultAddress":"Meir, 2000 Antwerp, Belgium","title":"Meir","address":"Meir, 2000 Antwerp, Belgium"}],"maxNumberOfPushPins":1,"shouldShowPushPinTitle":true,"zoomLevel":17,"mapType":"road","center":{"latitude":51.218780,"longitude":4.405590,"altitude":0,"altitudeReference":-1}}' 
  • Update the Web Part 

Apply the new configuration to the Bing Maps web part using the Set-PnPPageWebPart cmdlet. 

Set-PnPPageWebPart -Page $PageName -Identity $webPart.InstanceId -PropertiesJson $jsonProperty 

Conclusion 

Updating Bing Maps on SharePoint with PnP PowerShell offers a streamlined and efficient approach to manage dynamic content on your site. By automating this process, SharePoint administrators can ensure that their sites remain up-to-date and relevant, providing users with the most current and interactive information. 

Remember, the flexibility of PnP PowerShell allows for further customization and automation, making it an invaluable tool in your SharePoint toolkit. 

Script:  

#Parameters 

$SiteURL = "https://contoso.sharepoint.com" 

$PageName = "Home.aspx" 

$WebPartTitle = "Bing Maps" # Not the web part title, but name 

#Connect to SharePoint Online 

Connect-PnPOnline -Url $SiteURL -Interactive 

#Get the Page 

$Page = Get-PnPPage -Identity $PageName 

#Get the Web Part to update 

$webPart = $Page.Controls | Where-Object {$_.Title -eq $WebPartTitle} 

#Frame JSON to update 

$jsonProperty = '{"pushPins":[{"location":{"latitude":51.218780,"longitude":4.405590,"altitude":0,"altitudeReference":-1},"defaultTitle":"Meir","defaultAddress":"Meir, 2000 Antwerp, Belgium","title":"Meir","address":"Meir, 2000 Antwerp, Belgium"}],"maxNumberOfPushPins":1,"shouldShowPushPinTitle":true,"zoomLevel":17,"mapType":"road","center":{"latitude":51.218780,"longitude":4.405590,"altitude":0,"altitudeReference":-1}}' 

#Update Web Part properties 

Set-PnPPageWebPart -Page $PageName -Identity $webPart.InstanceId -PropertiesJson $jsonPorperty

Door Anouck

Een reactie achterlaten

Je e-mailadres zal niet getoond worden. Vereiste velden zijn gemarkeerd met *