Set modern page header author byline using PnP PowerShell

The script

The script to set the author byline in the header can be found here.

_AuthorByline field

Modern pages have a field called _AuthorByLine. When we set the value of this field of a page to the login name (or the email address) of a user, we will see the user details appear in the page header byline. However, as soon as we edit the page those details disappear (or the details of the user that were set before are shown).

PnP Core SDK

LayoutWebpartsContent field contains HTML content and to update that field we can rely on the PnP Core SDK. PnP have made our task easy by extracting the HTML content from LayoutWebpartsContent field and mapping them to properties in the PageHeader property of the page. The properties that we are interested in are Authors and AuthorByLine. We need to set these properties and save the page. This will then set the LayoutWebpartsContent property of the page.

Setting Authors and AuthorByLine properties

The Authors and AuthorByLine properties of PageHeader are of type String . We can set them using PnP PowerShell with the following lines of code.

Displaying user information

In the view mode, the page header byline gets the user information (like Name, Job Title) from the User Information List for user that is set. If the Job Title doesn’t appear then it might be because it is not yet updated in the User Information List. The information in the User Information List takes a few minutes to update/sync.

  • If the id in Authors is set to LoginName of the user (i.e. of the format i:0#.f|membership|... then the user information is obtained using the SharePoint user profile service using REST API (SP.UserProfiles.PeopleManager/GetPropertiesFor).

Summary

To display a user’s information in header byline of a modern SharePoint page, we need to set _AuthorByline and LayoutWebpartsContent field of the page. We can do that using PnP PowerShell by setting the Authors and AuthorByline properties of the PageHeader property of a page.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anoop

Anoop

154 Followers

Microsoft MVP. M365 Developer Architect at Content+Cloud.