Summary
This script allows you to connect to your SharePoint Online tenant and retrieve Message Centre 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
Pnp PowerShell
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Connect to SharePoint Online
Connect-PnPOnline -Url https://yourTenantName.sharepoint.com/ -Interactive
# Get Message Centre 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
}