I would like to update the Page Header Author of our SharePoint intranet news posts. I decided to try using Power Automate to achieve this.
It seems like this isn't in the properties of the page, but rather in the page content itself.
Is there any way this can be achieved using Power Automate?
You can use PnP PowerShell to set SharePoint page Author Byline. Here's the sample PnP PowerShell script for same:
Param(
[Parameter(mandatory = $true)]
[string]$SiteUrl,
[Parameter(mandatory = $true)]
[string]$PageName,
[Parameter(mandatory = $true)]
[string]$UserEmail
)
function Set-PageAuthorByline {
# Connect to the site
Connect-PnPOnline -Url $SiteUrl;
# If there is an error in the connection then return
if ($null -eq $(Get-PnPConnection).ConnectionType) {
return;
}
# Get the page object from the specified page name / url
$page = Get-PnPPage -Identity $PageName;
# Return if page is not found
if ($null -eq $page) {
Write-Error "Page Name is not valid";
return;
}
# Get the required user from the User Information list
Write-Host "Getting user information from User Information list..." -ForegroundColor Yellow;
$user = Get-PnPUser | Where-Object Email -eq $UserEmail;
if ($null -ne $user) {
Write-Host "Got user information from User Information list." -ForegroundColor Yellow;
}
else {
# If not user is not present in User Information list then add the user to the list
# This will not affect any permissions to the site
Write-Host "User information not present in User Information list, hence adding..." -ForegroundColor Yellow;
$user = New-PnPUser -LoginName $UserEmail;
# Return if the user is not found / email address is incorrect
if ($null -eq $user) {
Write-Error "User Name is not valid";
return;
}
}
Write-Host "Setting page header author..." -ForegroundColor Yellow;
# Set the Authors and AuthorByLine properties of the PageHeader
# Both these are string properties
$page.PageHeader.Authors = "[{`"id`":`"$($user.LoginName)`"}]";
$page.PageHeader.AuthorByLine = "[`"$($user.Email)`"]";
# Save the chnages and publish the page
$page.Save();
$page.Publish();
Write-Host "Done." -ForegroundColor Green;
Disconnect-PnPOnline;
}
Set-PageAuthorByline;
# Set-Page-Author-Byline.ps1 -SiteUrl https://tenantname.sharepoint.com/sites/sitename -PageName Page-1.aspx -UserEmail [email protected]
Source: Set Page Author Byline
Before running above script, you have to install PnP PowerShell by following: Installing PnP PowerShell