Add Yammer (Conversations) Feed to SharePoint Online Site Using PowerShell

Introduction

In this article, I would like to share the steps to add Conversations (Yammer) feed webpart in SharePoint modern page using PowerShell.

I got a requirement where I need to add conversation feed webpart and set up the conversation source like topic dynamically for multiple site pages.

I have 1000 site pages and I wanted to add a conversation webpart in all the pages based on different topic Id so conversation webpart will display different type of topic conversation for the respective pages.

Let’s start with a scenario in which I am going to explain how to use PowerShell script to add conversation webpart on site page.

Steps to Follow,

  • Create SharePoint connecction
  • Read CSV file
  • Add/Update yammer conversation webpart 

Excel file - We have excel file where I have stored Page Name and topic ID which I want to update using PowerShell script.

Here is sample excel file- "C:\SachinDevelopment\SiteUrlforYAmmer.csv"

SharePoint Page

We have created blank modern site pages in SharePoint Yammerfeev.aspx.

Add Conversations (yammer) Webpart in SharePoint Modern Page Using PowerShell

Script to update conversation webpart

Below is the script which we can use to add conversation webpart in modern site page.

Connect - PnPOnline - Url "Site URL here" - UseWebLogin[parameter(Mandatory = $false)][string] $CsvFilePath = "C:\SachinDevelopment\SiteUrlforYAmmer.csv"
#Loading CSV file
$csvItems = Import - Csv $CsvFilePath
foreach($Item in $csvItems) {
    $pageName = $Item.PageTitle
    $yammerid = $Item.TopicID
    $webParts = $pageName.Controls
    if ($webParts.Title - eq "Conversations") {
        Write - Host "Webpart already available : -"
        $pageName - f Red
    } else {
        $MyScript = '{"_type":"Topic","id":"' + $yammerid + '"}'
        $MyEncodedScript = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($MyScript))
        $jsonObj = '{"type":"Topic","showPublisher":true,"id":"' + $MyEncodedScript + '"}'
        Add - PnPClientSideWebPart - Page $item - DefaultWebPartType YammerFullFeed - WebPartProperties $jsonObj - Order 6 - Section 1 - Column 1
        Write - Host "Webpart added successfully  : -"
        $pageName - f Green
    }
}

Result

After running the script we can see conversation webpart added in respective site pages and display the yammer feed result on page based on Topic id we have used in excel column. It will automatically add same Topic id as conversation source topic as below.

Add Conversations (yammer) Webpart in SharePoint Modern Page Using PowerShell

Summary

In this article, we can understand and learn add/update Conversations feed webpart in modern SharePoint page using PowerShell.


Similar Articles