Jul 31 2018 02:19 AM - edited Oct 16 2018 04:54 AM
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).
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 Author
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).
Is there anyone who know how to define another field as Author for that "News" Modern Page ?
Fabrice Romelard
Jul 31 2018 06:43 AM
Jul 31 2018 07:07 AM
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
Aug 14 2018 11:28 AM - edited Jan 27 2019 03:54 AM
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?
Aug 14 2018 01:13 PM
Thanks for your message Vesa
I will check if that is working or not.
Fab
Aug 15 2018 09:13 AM - edited Aug 15 2018 09:19 AM
Dear Vesa,
I tried to follow your recommendation via the script I wrote:
[string]$SitePagesURL ="https://tenant.sharepoint.com/sites/SiteCollectionurl/subsite/" [string]$PageLibPublicName = "Site Pages" [int]$TempUserID = 0 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) } Load-DLLandAssemblies #get and save your O365 credentials [string]$username = "AdminLogin@tenant.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 " " $Alllists = $MyspoRootweb.Lists $MyPagelist = $Alllists.GetByTitle($PageLibPublicName) $MyPagelistItems = $MyPagelist.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) $Myctx.load($MyPagelistItems) $Myctx.executeQuery() foreach($PageItem in $MyPagelistItems) { Write-Host "ID:", $PageItem["ID"], " - Title:", $PageItem["Title"] $ModifiedByuser = $PageItem["Editor"] $CreatedByuser = $PageItem["Author"] if ($ModifiedByuser.LookupId -eq $CreatedByuser.LookupId) { Write-Host " ===> Modified by: ", $ModifiedByuser.LookupValue, "[", $ModifiedByuser.LookupId, "] - Created by:", $CreatedByuser.LookupValue, "[", $CreatedByuser.LookupId, "]" -ForegroundColor Yellow } else { $TempUserID = $ModifiedByuser.LookupId Write-Host " ===> Modified by: ", $ModifiedByuser.LookupValue, "[", $ModifiedByuser.LookupId, "] - Created by:", $CreatedByuser.LookupValue, "[", $CreatedByuser.LookupId, "]" -ForegroundColor Red $PageItem["Author"] = $TempUserID $PageItem.Update(); $Myctx.ExecuteQuery(); } }
But nothing change at the "Created by" level, the change is apply for the "modified by" with my admin account used for that script execution.
So my issue is not solved and i'm showing only the script execution account as news publisher.
Thanks for your help if you have another way.
Fab
Aug 16 2018 04:23 AM
Seems that your user resolution is not properly done as following did work without any issues. I just tested it in a normal E3 tenant in production. Just used the basic code provided from the blog post for proof of concept.
// Get pwd from environment variable, so that we do not need to show that. string pwd = "pwdfortheaccount"; // Get access to source site using (var ctx = new ClientContext("https://contoso.sharepoint.com/sites/OverrideTest")) { //Provide count and pwd for connecting to the source var passWord = new SecureString(); foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c); ctx.Credentials = new SharePointOnlineCredentials("whatever@contoso.onmicrosoft.com", passWord); var list = ctx.Web.GetList("/sites/OverrideTest/SitePages"); ListItem item = list.GetItemById(1); ctx.Load(item); ctx.ExecuteQuery(); User user = ctx.Web.EnsureUser("i:0#.f|membership|admin@contoso.onmicrosoft.com"); ctx.Load(user); ctx.ExecuteQuery(); item["Modified"] = DateTime.Now.AddYears(-5); item["Created"] = DateTime.Now.AddYears(-5); item["Editor"] = user.Id; item["Author"] = user.Id; item.Update(); ctx.ExecuteQuery(); }
This resulted updated values as seen in this picture below... with updated values for Modified By and Created By.... I was using my personal account (Vesa) and set the account for the item as "James Admin". I would simply double check the identity values in your tenant for the person using, for example, user profile admin UIs... and then test things in simplistic code like above... before making the script too complex. First POC - then polishing.
Aug 16 2018 06:34 AM
Dear Vesa,
Thanks for your message, I tried to use it adapting to my case, but that is driving me mad.
Now I can confirm the xxx.update() is changing the title, but nothing related to the Author
The adapted code is the following one:
[string]$SitePagesURL ="https://tenant.sharepoint.com/sites/SiteCollection/Subsite/" [string]$PageLibPublicName = "Site Pages" [int]$TempUserID = 0 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) } Load-DLLandAssemblies #get and save your O365 credentials [string]$username = "login@tenant.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 " " $Alllists = $MyspoRootweb.Lists $MyPagelist = $Alllists.GetByTitle($PageLibPublicName) $MyPagelistItems = $MyPagelist.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) $Myctx.load($MyPagelistItems) $Myctx.executeQuery() foreach($PageItem in $MyPagelistItems) { $ModifiedByuser = $PageItem["Editor"] $CreatedByuser = $PageItem["Author"] $MyEditoruserAccount = $MyspoRootweb.EnsureUser($ModifiedByuser.LookupValue); $Myctx.load($MyEditoruserAccount) $Myctx.executeQuery() if ($ModifiedByuser.LookupId -eq $CreatedByuser.LookupId) { #Write-Host " ===> Modified by:", $ModifiedByuser.LookupValue, "[", $ModifiedByuser.LookupId, "] - Created by:", $CreatedByuser.LookupValue, "[", $CreatedByuser.LookupId, "]" -ForegroundColor Yellow #Write-Host " ===> Modified Account Login:", $MyEditoruserAccount.LoginName -ForegroundColor Magenta } else { Write-Host "ID:", $PageItem["ID"], " - Title:", $PageItem["Title"] Write-Host " ===> Modified by:", $ModifiedByuser.LookupValue, "[", $ModifiedByuser.LookupId, "] - Created by:", $CreatedByuser.LookupValue, "[", $CreatedByuser.LookupId, "]" -ForegroundColor Red Write-Host " ===> Modified Account Login:", $MyEditoruserAccount.LoginName -ForegroundColor Magenta $PageItem["Title"] = $PageItem["Title"] + " XXXXX" # < CHANGE IS OK $PageItem["Author"] = $MyEditoruserAccount.Id # < CHANGE IS NOT OK !!! $PageItem.Update() $Myctx.ExecuteQuery() } }
But are you sure that option is sustainable for the future, because I will have to execute that script each time someone modify one of the help page, and I have no idea when they will do that.
Is there any plan to evaluate the showing of the Modified by instead ?
Fab
Aug 21 2018 11:33 AM
I'm also trying to find a way to modify the "Author" of a News article. Came across this post on the Uservoice site and it's flagged as "in the plans". Promising, but I guess we can't expect much until it hits the Office 365 Roadmap. https://sharepoint.uservoice.com/forums/329214-sites-and-collaboration/suggestions/31875550-change-p...
Oct 16 2018 04:53 AM - edited Oct 16 2018 06:09 AM
SolutionDear 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
Oct 22 2018 08:27 AM
The Author field never gets updated for me. The code runs fine.
Oct 23 2018 03:23 AM
It's difficult to give you support without any knowledge of your tenant.
The best way is to user the log writing to follow the execution and find what could be the reason for that issue you observed.
From my side, the change was applied and I validated that script on several different sites without hundreds of pages.
It's now running in another production script too.
Fab
Nov 27 2018 07:48 AM
I have the same problem. I use the below PowerShell script to set the publishing information (Author and Date) of a News page.
#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()
}
}
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")
Jan 29 2019 06:02 AM
Hello Fabrice,
With the recent configuration changes added to Modern Pages, you can now specify a news author which overrides the "created by" information displayed in the News web part.
However it does not work for news which are just simple links but it works well for Modern pages.
Not that this new parameter does not allow you to change the displayed date, so your script is still very useful!
Jan 09 2020 11:22 AM
@Alexander AurasAfter some research and tests, I arrived at with my simple recipe.
After 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!?
Apr 20 2020 09:52 AM
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
Jul 23 2020 10:18 AM
@Hugo Reyes You can just close the author section by clicking the "X" and it won't display.
Aug 28 2020 05:06 AM
That is great in the browser, what about PowerShell? How can you do it with code?
Aug 28 2020 08:32 AM - edited Aug 28 2020 08:33 AM
@Robert Vončina Try leaving the author byline field blank, maybe?
#Parameters
$SiteURL= "https://xxx.sharepoint.com/sites/xxx"
$ListName = "SitePages"
$ItemID = "xx"
$_AuthorByline = " "
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin
Set-PnPListItem -List $ListName -Identity $ItemID -Values @{"AuthorByline"=$_AuthorByline}
Aug 30 2020 12:27 PM
Tried that already, doesn't work. The page still shows the author...
Oct 16 2018 04:53 AM - edited Oct 16 2018 06:09 AM
SolutionDear 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