Forum Discussion
RESOLVED: How to change Modern page Author from the "Created By" field to something else
When we use the Modern Pages to Publish news, we can see the WebPart "Last Published News" with a vignette (Image, Title, first part of the text and Author).
Modern Home Page News
The issue is this value when you use an automation system to create the site canevas, because the News Author will stay with the "Created By" field as Author which is in my case the account used for the PowerShell script.
As you can see in that picture, I modified some pages with my standard account and the Home Page Webpart shows only the admin account as AuthorList of Modern pages published as news
The "See All" link placed into the Last news WebPart is pointing an aggregated view of all the published news and you can see into the Author shows only the "Created by" field (my admin account).See all Published News
Is there anyone who know how to define another field as Author for that "News" Modern Page ?
Fabrice Romelard
Dear all,
I finally found how to do that change based on a PowerShell script.
This script will directly check the page list and for each item will check if the "Modified By" value is different than the "Created By", and check also if the "created by" account was not an admin (or system).
If yes, the item fields (Author, Creator) will be updated with the values "Modified By" and the Modified Date will be applied into all the fields using the same type.
You can easily adapt that script code if you need another logic, but the solution is working really well and I applied it in many Modern Page List.
[string]$SitePagesURL ="https://[yourtenant].sharepoint.com/sites/YourSiteColl/YourSubsite" [string]$PageLibPublicName = "Site Pages" [DateTime]$modifiedDate = Get-Date [string]$DefaultEmailAddress = "PublisherEmail@yourdomain.com" [string]$MyTempEmailAddress = "" # --------------------------------------------------------------------------------------------------------------- function Load-DLLandAssemblies { [string]$defaultDLLPath = "" # Load assemblies to PowerShell session $defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll" [System.Reflection.Assembly]::LoadFile($defaultDLLPath) $defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll" [System.Reflection.Assembly]::LoadFile($defaultDLLPath) $defaultDLLPath = "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll" [System.Reflection.Assembly]::LoadFile($defaultDLLPath) } # --------------------------------------------------------------------------------------------------------------- Function Get-All-PageList-UpdateMetadata($MyctxTemp, $MyspoRootwebTemp) { $Alllists = $MyspoRootwebTemp.Lists $MyPagelist = $Alllists.GetByTitle($PageLibPublicName) $MyQuery = New-Object Microsoft.SharePoint.Client.CamlQuery; $MyQuery.ViewXml = "<View><Query><OrderBy><FieldRef Name='Modified' Ascending='FALSE'></FieldRef></OrderBy></Query><RowLimit>9999</RowLimit></View>" $MyPagelistItems = $MyPagelist.GetItems($MyQuery); $MyctxTemp.load($MyPagelistItems) $MyctxTemp.executeQuery() foreach($PageItem in $MyPagelistItems) { Write-Host "" Write-Host "" Write-Host " --------------------------------------------------------- " <# foreach($MyFieldval in $PageItem.FieldValues) { Write-Host " >>> FieldName:", $MyFieldval } #> $modifiedDate = $PageItem["Modified"] $ModifiedByuser = [Microsoft.SharePoint.Client.FieldUserValue]$PageItem["Editor"] $CreatedByuser = [Microsoft.SharePoint.Client.FieldUserValue]$PageItem["Author"] Write-Host "ID:", $PageItem["ID"], "- Title:", $PageItem["Title"], "- Original Publication Date:", $modifiedDate.ToString("dd-MM-yyyy") Write-Host " ==>>> PromotedState:", $PageItem["PromotedState"], "- PageLayoutType:", $PageItem["PageLayoutType"] -ForegroundColor red Write-Host " >> Description:", $PageItem["Description"] Write-Host " >> BannerImageUrl:", $PageItem["BannerImageUrl"].URL, "- URLDesc:", $PageItem["BannerImageUrl"].Description Write-Host " >> ContentTypeId:", $PageItem["ContentTypeId"] if ($ModifiedByuser.LookupId -ne $CreatedByuser.LookupId) { Write-Host " ===> Modified by:", $ModifiedByuser.LookupValue, " - ", $ModifiedByuser.Email ,"[", $ModifiedByuser.LookupId, "]" -ForegroundColor green Write-Host " ===> Created by:", $CreatedByuser.LookupValue, " - ", $CreatedByuser.Email ,"[", $CreatedByuser.LookupId, "]" -ForegroundColor green if($ModifiedByuser.Email -ne "") { $MyTempEmailAddress = $ModifiedByuser.Email } else { $MyTempEmailAddress = $DefaultEmailAddress #Admin Account to reset with the default one } $MyEditoruserAccount = $MyspoRootwebTemp.EnsureUser("i:0#.f|membership|$($MyTempEmailAddress)"); $MyctxTemp.load($MyEditoruserAccount) $MyctxTemp.executeQuery() Write-Host " ===> Modified Account Login:", $MyEditoruserAccount.LoginName -ForegroundColor Magenta $PageItem["Modified"] = $modifiedDate; $PageItem["Created"] = $modifiedDate; $PageItem["FirstPublishedDate"] = $modifiedDate; $PageItem["Created_x0020_By"] = $MyEditoruserAccount.LoginName $PageItem["Modified_x0020_By"] = $MyEditoruserAccount.LoginName $PageItem["Editor"] = $MyEditoruserAccount.Id; $PageItem["Author"] = $MyEditoruserAccount.Id $PageItem.Update() $MyctxTemp.ExecuteQuery() } else { Write-Host " ===> Modified by:", $ModifiedByuser.LookupValue, " - ", $ModifiedByuser.Email ,"[", $ModifiedByuser.LookupId, "]" -ForegroundColor red Write-Host " ===> Created by:", $CreatedByuser.LookupValue, " - ", $CreatedByuser.Email ,"[", $CreatedByuser.LookupId, "]" -ForegroundColor red if($ModifiedByuser.Email -eq "") #Admin Account to reset with the default one { $MyTempEmailAddress = $DefaultEmailAddress $MyEditoruserAccount = $MyspoRootwebTemp.EnsureUser("i:0#.f|membership|$($MyTempEmailAddress)"); $MyctxTemp.load($MyEditoruserAccount) $MyctxTemp.executeQuery() Write-Host " ===> Modified Account Login:", $MyEditoruserAccount.LoginName -ForegroundColor Magenta $PageItem["Modified"] = $modifiedDate; $PageItem["Created"] = $modifiedDate; $PageItem["FirstPublishedDate"] = $modifiedDate; $PageItem["Created_x0020_By"] = $MyEditoruserAccount.LoginName $PageItem["Modified_x0020_By"] = $MyEditoruserAccount.LoginName $PageItem["Editor"] = $MyEditoruserAccount.Id; $PageItem["Author"] = $MyEditoruserAccount.Id $PageItem.Update() $MyctxTemp.ExecuteQuery() } } Write-Host " --------------------------------------------------------- " } } # --------------------------------------------------------------------------------------------------------------- Load-DLLandAssemblies #get and save your O365 credentials [string]$username = "adminAccount@[yourtenant].onmicrosoft.com" [string]$PwdTXTPath = "C:\SECUREDPWD\ExportedPWD-$($username).txt" $secureStringPwd = ConvertTo-SecureString -string (Get-Content $PwdTXTPath) $cred = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd #connect to the web site using the stored credentials Write-host " " Write-host " -------------------------------------------------------------------------------------------- " -ForegroundColor green Write-host " ---- CONNECT THE SITE --- " -ForegroundColor green Write-host " CONNECTED SITE:", $SitePagesURL -ForegroundColor Yellow $Myctx = New-Object Microsoft.SharePoint.Client.ClientContext($SitePagesURL) $Myctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($cred.UserName,$cred.Password) $Myctx.RequestTimeout = 1000000 # milliseconds $MyspoRootweb = $Myctx.Web $Myctx.Load($MyspoRootweb) $Myctx.ExecuteQuery() Write-Host " " Write-Host " ---------------------------------------------------------" Write-Host " >>>> # Server Version:" $Myctx.ServerVersion " # <<<<<<" -ForegroundColor Green Write-Host " ---------------------------------------------------------" Write-Host " " Write-host " -------------------------------------------------------- " Write-host " -->> RootSite:", $MyspoRootweb.URL -ForegroundColor green Write-host " " Get-All-PageList-UpdateMetadata $Myctx $MyspoRootweb
Thanks all for your help.
French version of the article:
Fabrice Romelard
19 Replies
- Alexander AurasIron Contributor
I have the same problem. I use the below PowerShell script to set the publishing information (Author and Date) of a News page.
Script
#requires -Modules "SharePointPnPPowerShellOnline"
function Set-PublishingInformation {
[CmdletBinding()]
param (
[string] $Site,
[string] $Page,
[string] $Publisher,
[DateTime] $PublishingDate
)
begin {
Connect-PnPOnline -Url $Site -UseWebLogin
$ctx = Get-PnPContext
$web = Get-PnPWeb
$user = $web.EnsureUser($Publisher)
$ctx.Load($user)
$ctx.ExecuteQuery()
}
process {
$item = (Get-PnPClientSidePage $Page).PageListItem
$item.File.CheckOut()
$item["_AuthorByline"] = $user.Id
$item["FirstPublishedDate"] = [TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($PublishingDate, "Pacific Standard Time")
$item.Update()
$item.File.CheckIn("Publishing information updated by script", "MajorCheckIn")
$ctx.ExecuteQuery()
}
}Example Usage
Import-Module SharePointPnPPowerShellOnline
Set-PublishingInformation -Site "https://<tenant>.sharepoint.com/sites/<your_site>" -Page "Your-promoted-News-Page" -Publisher "bill.jones@<domain>.com" -PublishingDate (Get-Date "10/26/2018 16:00")- kmktnnIron Contributor
Alexander AurasAfter some research and tests, I arrived at with my simple recipe.
Connect-PnPOnline https://TENANT.sharepoint.com/sites/SiteName$listItemID = 0
$PageName = "PageURLwithoutASPX"
$DesiredDate = Get-Date "2019-11-22 09:00:00"
$EmailUser = "Edward.Snowden@saveus.com"Set-PnPListItem -List "Site Pages" -Identity $listItemID -Values @{
"Created"=$DesiredDate;
#"Modified"=$DesiredDate;
"FirstPublishedDate"=$DesiredDate;
"Editor"=$EmailUser;
"Author"=$EmailUser;
"_AuthorByline"=$EmailUser;
#"PromotedState" = "0"
}Set-PnPClientSidePage -Identity $PageName -PublishAfter running this script, a new version will be published (with the comment 'Published by provisioning') and the 'Modified by' (Editor) and 'Modified' fields will be updated by the user that ran the script.
You can comment out some of the lines when you don't wish to update some values.
However!! In order to change the 'Author' you must keep the 'Editor' line!?
- Hugo ReyesCopper Contributor
Hey there, quick question.
what of I want to hide the "author" I dont want it to be displayed, Is there a way to do this?
Tks
HReyes
- DeletedNope. Have same issue and we just had to live with it for now. I tried css injection but the css used for that field used some dynamic css class and can’t be used as it changes every so often.
The only thing I know that might be possible or using the rest call in flow but not sure it works SPO. I read up on it And decided it wasn’t worth the effort :p.
Last option is finding or creating your own news webpart.- FromelardIron Contributor
Thanks Christopher,
The built-in web part does not give any parameter for that and the "See all" link is pointing also a built-in page impossible to change.
I also check the page content type and found 2 "Author" fields, but without any change possible into.
So, from my knowledge, the only way is to look from MS to change that setting.
Except if someone has another genius idea :)
Fab
- VesaJuvonen
Microsoft
If you are looking into updating the Created By / Modified By fields, that is actually possible with PowerShell / CSOM with the sufficient permissions. See the following blog post for additional details.
Would that solve your scenario?