Prerequisites
Before we get started, there are a few prerequisites that you will need:
- A SharePoint Online site where you have permission to create and edit news pages.
- PowerShell 7.2 or later installed on your computer.
- The PnP.PowerShell module installed on your computer.
The Script
The PowerShell script below demonstrates how to change the first publish date of a news page in SharePoint Online:
|
|
The script starts by setting the new publish date and the ID of the news item to update. You will need to modify these values to match your specific scenario.
Next, the script connects to the SharePoint site using PnP-PowerShell and retrieves the news item in English. The script then updates the news item with the new publish date using the Set-PnPListItem cmdlet.
The script then checks if the news item has any translations. If there are translations, the script retrieves the UniqueId of the English news item and uses it to get the translated news items. The script then updates each translated news item with the new publish date using the Set-PnPListItem cmdlet.
Conclusion
In this blog post, we explored how to use PowerShell to change the first publish date of a news page in SharePoint Online. This can be a useful tool for updating the publish date of a news page to reflect changes in the content or to correct errors in the original publish date.
By using PowerShell and the PnP PowerShell module, you can automate this process and save time and effort when managing your SharePoint Online news pages.