Create SharePoint news links using PnP PowerShell

As explained in the previous article there are a variety of scenarios that can be implemented using SharePoint news links, by simply reposting something that is already available in your intranet or publicly in the web.

In this article I’ showing how SharePoint news links can be created using PnP PowerShell and this way used in automation processes to post information to SharePoint that is available elsewhere.

Create SharePoint news links using PowerShell

In order to accomplish the steps described in this article you must install the latest version of the PnP PowerShell module, more information about how to do it can be found here.

  1. Open the PowerShell command line
  2. Execute the following cmdlet to connect to the SharePoint site collection where the news link will be created
    Connect-PnPOnline -url https://contoso.sharepoint.com
  3. Copy and execute the following script, updating the variables to include information from the original post
    • newsLinkTitle – The title of the original post (110 character limit)
    • newsLinkURL – The url of the original post
    • newsLinkThumbnailURL – A representative image of the post to be used in the SharePoint news web part and other news locations in Microsoft 365
    • newsLinkDescription – A description of the original post (250 character limit)
    $newsLinkTitle = "My Life at Apple And the Steve I Knew"
    $newsLinkURL = "https://handsontek.net/reading-corner-life-apple-steve-knew/"
    $newsLinkThumbnailURL = "https://handsontek.net/images/hot2/AppleBook/my%20life%20at%20apple.jpeg"
    $newsLinkDescription = "This type of post is a first for me, I've never did a book review even though I'm a book addict and a book author. From now on, in this space you will find book reviews that somehow relate with technology, management or any other topic I'm into. The first book review is about My Life at Apple: And the Steve I Knew a memoir written by John Couch, a former Apple executive that was employee number 54 and worked at the company for more than 20 years."
    
    $newsLink = Add-PnPPage -Name $newsLinkTitle.substring(0, [System.Math]::Min(110, $newsLinkTitle.Length)) -LayoutType RepostPage 
    $newsLink.RepostSourceUrl = $newsLinkURL
    $newsLink.ThumbnailUrl = $newsLinkThumbnailURL
    $newsLink.RepostDescription = $newsLinkDescription.substring(0, [System.Math]::Min(250, $newsLinkDescription.Length))
    $newsLink.Save() 
    $newsLink.Publish()
    

Create SharePoint news links using PowerShell

Once created you will be able to see the news link post in the Site Pages library of the site collection and it will show up next to other SharePoint news in Microsoft 365.


No comments yet

Leave a Reply


I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.

%d bloggers like this: