Auto Delete Message From Yammer Community with PowerShell
I was recently tasked with clearing out a Yammer Communities auto-welcoming posts. If you are not familiar with auto-welcoming posts, Yammer used to automatically post a message whenever someone joined a community. It looked something like this, “Bradley Wyatt joined the Lazy Administrator network. Take a moment to welcome Brad.”
Thankfully, Microsoft removed this feature so your community is not littered with auto welcoming messages anymore. But, if your community existed prior to this change you may be faced with hundreds, if not thousands of these posts that you may want to remove.
- Register a New App so we can interface with the Yammer API
- Next, click “Generate a developer token for this application.” Save the token for later as you will need it.
- Next, navigate to the Yammer Admin page and click “Export Network Data” under Content and Security.
- Select the date range you want to export the data from. In my case, we are just starting to use Yammer so I will export all data. Once you have selected the range, click Export.
- Unzip the folder it downloads and open the Mesages.csv file.
- In my example, I want to delete all message in the “All Company” community. The All Company community can be found as it will have no group_name associated to the messages. I can also delete automated messages by selecting messages generated by ‘system’ under message_type
- Use the script below and add your token you got earlier to the personalToken variable. Modify where your CSV lives as well. You can also feed it messageIDs one at a time if you would like.
[string]$personalToken = '8623024-xd5QbsuvdWlvNKvg' Function Get-Token() { $headers = @{ Authorization=("Bearer " + $personalToken) } return $headers } Function Remove-YammerMessage($messageId) { $headers = Get-Token return Invoke-WebRequest –Uri "https://www.yammer.com/api/v1/messages/$($messageId)" –Method Delete -Headers $headers } #Grab all message IDs from my All Company community $messages = Import-Csv -Path "$env:HOME\Downloads\export-1661462628568\Messages.csv" | where-object {$_.group_name -eq ""} foreach ($i in $messages) { Remove-YammerMessage $i.id }
- Going back to by Community after it has been ran, I can see that all my messages are deleted.
The PowerShell code source can be found at the following blog. Make sure to check them out!
My name is Bradley Wyatt; I am a 5x Microsoft Most Valuable Professional (MVP) in Microsoft Azure and Microsoft 365. I have given talks at many different conferences, user groups, and companies throughout the United States, ranging from PowerShell to DevOps Security best practices, and I am the 2022 North American Outstanding Contribution to the Microsoft Community winner.