Office 365: Comment changer le nom “Auteur” dans les pages modernes d'un Modern Site SharePoint Online
Office 365 SharePoint Online propose désormais l’usage des sites Modernes accompagnés des pages Modernes.
Ces pages peuvent alors être utilisées comme des News et donc présentées aux utilisateurs de manière sympathique.
Le fait est que ce mode de fonctionnement est moins souple que les pages de “Publishing” et certaines fonctionnalités ne sont pas intégrées, dont la désignation du “Publieur”.
En effet, par défaut le nom qui sera montré sera toujours le créateur de la news:
Le script PowerShell suivant vous permet de changer la valeur Auteur par le nom de la dernière personne ayant édité la News.
De même que la date de publication deviendra celle de modification.
[string]$SitePagesURL =”https://[yourtenant].sharepoint.com/sites/SiteCollection”
[string]$PageLibPublicName = "Site Pages"
[DateTime]$modifiedDate = Get-Date[string]$DefaultEmailAddress = "Fabrice.Romelard@sgs.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 = "9999"
$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 greenif($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 redif($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@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 greenWrite-host " "
Get-All-PageList-UpdateMetadata $Myctx $MyspoRootweb
Vous pouvez l’adapter à vos besoins.
Fabrice Romelard
Message en Anglais:
Commentaires
Enregistrer un commentaire