Microsoft 365 – PowerShell script to convert news posts to site page

Converting news post to site page
Converting news post to site page

Hi All,

Greetings.

Today sharing small but important PowerShell script.

PowerShell script – How to convert the news post to site page.

Background:

One of our user wanted to create the content page, but it was mistakenly posted as a news post. Since a news post behaves differently from a content page, the user wants to convert the news post into a content page (site page) instead of deleting it and creating a new page.

So, we came up with the PnP PowerShell approach.

This is two step process.

Type of page / post is identified by its “PromotedState” property. So we need to update the “PromotedState” property of the post.

Detailed Steps:

  • Connect to the tenant
  • Update the “PromotedState” property of the news post
    • PromotesState” – 2 is for news post
    • PromotesState” – 0 is for site page / content page
  • We need to know the ID of the news post which we need to convert to site page
Screenshot of the Knowledge Junction site pages overview, displaying page names, authors, modification times, and promotion status.
Image 1: News post which we will convert to Content Page. ID of news post = 41, Promoted State = 2

Connect to the tenant

  • Here I’ll use Connect-PnPOnline PnP PowerShell CMDLET to connect to my tenant
  • I am using
    • Client / App ID
    • Certificate
Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com/sites/knowledgejunctiondemo
-ClientId $clientid #my client id
-CertificatePath $certificatepath #path of my certificate from my local drive
-CertificatePassword $certificatepassword #password of my certificate
-Tenant 'knowledgejunction1.onmicrosoft.com' #tenant
-WarningAction Ignore

Update the “PromotedState” property of the news post

Once we connected successfully to the tenant, we will convert the news post.

We will set “PromotedState” property to 0 (Zero) as

Set-PnPListItem -List "SitePages" -Identity 41 -Values @{"PromotedState"="0"}

As we will execute the above CMDLET, we will see the updated “PromotedState” property.

Screenshot of a site pages interface in SharePoint, displaying a list of pages created by Prasham Sabadra, including 'Demo---Converting-News-P' with modification and creation dates.
Image 2: News post converted to Content Page. ID of post = 41, Promoted State = 0

PS C:\> $certificatepassword = (ConvertTo-SecureString -AsPlainText $certificatepassword -Force)

PS C:\> Connect-PnPOnline -Url https://knowledgejunction1.sharepoint.com 
                          -ClientId $clientid 
                          -CertificatePath $certificatepath 
                          -CertificatePassword $certificatepassword 
                          -Tenant 'knowledgejunction1.onmicrosoft.com' 
                          -WarningAction Ignore

PS C:\> Set-PnPListItem -List "SitePages" -Identity 41 
                        -Values @{"PromotedState"="0"}

Id    Title                                              GUID
--    -----                                              ----
41    Demo - Converting News Post to Content Page        b58220ff-94b4-4496-ba8d-b47d5384590e

A command line interface displaying PowerShell commands related to connecting to SharePoint and managing a SharePoint list item, including setting a promoted state for a news post.
Image 3: PowerShell CMDLETs

Thank You 🙂 Have a Great time ahead 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading