Retrieve Message Center announcements and post to MS Teams channel
Summary
This script allows you to connect to your SharePoint Online tenant and retrieve Message Center announcements. It then connects to Microsoft Teams and loops through the announcements, posting them to a specific Teams channel.
Implementation
- Create csv file with the list of site collection URLs to enable app catalog
- Open Windows PowerShell ISE
- Create a new file
- Copy the code below
- Save the file and run it
# Connect to SharePoint Online
Connect-PnPOnline -Url https://yourTenantName.sharepoint.com/ -Interactive
# Get Message Center announcements
$announcements = Get-PnPMessageCenterAnnouncement | Where-Object { $_.Category -eq "PlanForChange" } | Select-Object Title, Description
# Connect to teams
Connect-MicrosoftTeams
# Loop through the announcements and post to Teams channel
foreach ($announcement in $announcements) {
$message = "$($announcement.Title): $($announcement.Description)"
Submit-PnPTeamsChannelMessage -Team "TeamID" -Channel "General" -Message $message
}
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Valeras Narbutas |
Nanddeep Nachan |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.