SOLVED

Using PowerShell to change page banner image

Copper Contributor

Hi Folks,

Currently have a automatic site creation tool up and running. I know using the PnP engine no content will be included in the template, but is there any way on the newly created site on the main home page (Modern Page) I can change the banner image using PowerShell to reference an image stored somewhere else?

Thanks!

4 Replies

FYI, while not exactly what you are looking for, there are some new features rolling out that you may find helpful, see

Updated feature: we're rolling out new SharePoint Online site branding and navigation features
MC165552
 
Published On : November 19, 2018
best response confirmed by Blair24 (Copper Contributor)
Solution

Blair,

I believe you are trying to change home page banner image programmatically. You can use PnP Powershell to do that. Follow below steps:

 

1. Connect your site using
     Connect-PnPOnline -Url $siteUrl -Credential $credential

2. Get Client Side Page
    $myHomePage = Get-PnPClientSidePage -Identity Home.aspx

3. Set custom page header:
   $myHomePage.SetCustomPageHeader('<Server relative Image URL>')

4. Save the page:
     $myHomePage.Save()

5. Publish:
     $myHome.Publish()

 

 

Let me know if it helped.

Hi Rahul,

 

Thanks for the response.

Dropped the Publishing from the script and worked.

 

Cheers!

@Blair24 @Rahul Suryawanshi @Dean Gross Hi all,

setting the page banner image in this way is working, but if you do it on a news page and the news will be visible in the news web part, the picture is missing. Does anybody know how to fix this?

Thanks a lot in advance and kind regards, Sebastian

1 best response

Accepted Solutions
best response confirmed by Blair24 (Copper Contributor)
Solution

Blair,

I believe you are trying to change home page banner image programmatically. You can use PnP Powershell to do that. Follow below steps:

 

1. Connect your site using
     Connect-PnPOnline -Url $siteUrl -Credential $credential

2. Get Client Side Page
    $myHomePage = Get-PnPClientSidePage -Identity Home.aspx

3. Set custom page header:
   $myHomePage.SetCustomPageHeader('<Server relative Image URL>')

4. Save the page:
     $myHomePage.Save()

5. Publish:
     $myHome.Publish()

 

 

Let me know if it helped.

View solution in original post