0

I have tried the following but it doesn't change the actual image on the page when you view it in the browser.

Set-PnPListItem -List "SitePages" -Id 2 -Values @{"BannerImageUrl" = " https://contoso.sharepoint.com/sites/mycomsite3/bannerimages/bread-braid-tedster-sml.jpg";}

What this code does do is change the value you see for page ID2 when you use this code.

# Get alist of all pages and their banner URLs
$items = Get-PnPListItem -List "SitePages" -Fields ID,Title,BannerImageUrl
$items | %{new-object PSObject -Property @{Id=$_["ID"];Title=$_["Title"];BannerImageUrl=$_["BannerImageUrl"].Url}} | select ID,Title,BannerImageUrl

My guess is that there is a property related to set-PNPClientSidePage that also needs changing.

Your help suggestions on how to use PNP commandlets would be greatly appreciated.

Cmdlet versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     2.18.17... SharePointPnPPowerShell2016         {Add-PnPContentType, Add-PnPContentTypeToDocumentSet,
    Directory: C:\Users\<user>\AppData\Local\Apps\SharePointPnPPowerShellOnline\Modules
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     2.18.17... SharePointPnPPowerShellOnline       {Add-PnPClientSidePage, Add-PnPClientSidePageSection,
    Directory: C:\Program Files\WindowsPowerShell\Modules
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Binary     2.18.17... SharePointPnPPowerShellOnline       {Add-PnPClientSidePage, Add-PnPClientSidePageSection,
Binary     2.17.17... SharePointPnPPowerShellOnline       {Add-PnPContentType, Add-PnPContentTypeToDocumentSet,

Cmdlet install

I think I’ve used the install-module method.

NOTE: I am not trying to remove the banner, that is easy to do using the UI (click the x below the image icon in the page edit view).

2
  • I've checked using SharePoint designer and when I run code like the following Set-PnPListItem -List "SitePages" -Id 29 -Values @{"BannerImageUrl" = "";} The code within the ASPX page is modified to <mso:BannerImageUrl msdt:dt="string"></mso:BannerImageUrl> But the page when viewed in the browser doesn't show no bannerimage. Commented Sep 28, 2017 at 22:05
  • It's also logged in pnp as an open issue - github.com/SharePoint/PnP-Sites-Core/issues/1464 Commented Jan 15, 2018 at 0:44

1 Answer 1

0
$page = Get-PnPClientSidePage -Identity Home.aspx
$lwc = $page.PageListItem.FieldValues.LayoutWebpartsContent
$newLwc = $lwc -replace "&quot;imageSourceType&quot;&#58;4,&quot;", "&quot;imageSourceType&quot;&#58;0,&quot;"
Set-PnPListItem  -List "SitePages" -Id $page.PageId -Values @{"LayoutWebpartsContent" = $newLwc} -SystemUpdate

This code here should remove the image from the page. ImageSourceType = 4 is default, ImageSourceType = 0 is none, ImageSourceType = 2 is custom image.

The answer was inspired from https://github.com/pnp/PnP-Sites-Core/issues/1464

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.