Skip to content
The Lazy Administrator
  • Home
  • Disclaimer
  • Contact
  • About Me
  • Search Icon

The Lazy Administrator

Finding ways to do the most work with the least effort possible

Auto Delete Message From Yammer Community with PowerShell

Auto Delete Message From Yammer Community with PowerShell

August 25, 2022 Brad Wyatt Comments 0 Comment

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.

  1. Register a New App so we can interface with the Yammer API
  2. Next, click “Generate a developer token for this application.” Save the token for later as you will need it.
  3. Next, navigate to the Yammer Admin page and click “Export Network Data” under Content and Security.
  4. 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.

  5. Unzip the folder it downloads and open the Mesages.csv file.
  6. 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
  7. 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
    }
  8. 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!

 

Brad Wyatt
Brad Wyatt

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.


PowerShell, Yammer
API, Office 365, PowerShell, Yammer

Post navigation

PREVIOUS
Improved External Email Tagging in Office 365
NEXT
Office 365 / Exchange Online Mailbox Size Report Including Mailbox Free Space with PowerShell

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Subscribe

Email


Categories

  • Active Directory (8)
  • AI (3)
  • API (1)
  • AutoPilot (2)
  • Azure (15)
  • Bicep (4)
  • Connectwise (1)
  • Defender for Cloud Apps (1)
  • Delegated Admin (1)
  • DevOps (6)
  • Graph (6)
  • Intune (15)
  • LabTech (1)
  • Microsoft Teams (6)
  • Office 365 (19)
  • Permissions (2)
  • PowerShell (50)
  • Security (1)
  • SharePoint (3)
  • Skype for Business (1)
  • Terraform (1)
  • Uncategorized (2)
  • Yammer (1)

Recent Comments

  • Mike D on Upload a file to Connectwise and Attach it to a Service Ticket with PowerShell
  • Side Eye on Homeland Security’s Trusted Travelers API and PowerShell – Getting a Better Global Entry Interview Using PowerShell
  • Lisa on Allow Non-Admin Users to Manage Their Desktop Icons Using Intune
  • A1 Lottery LOGIN on Get a New Computer’s Auto Pilot Hash Without Going Through the Out of Box Experience (OOBE)
  • Kristopher Gates on Getting Started with GitHub Copilot in the CLI

1,752,855 People Reached

© 2025   All Rights Reserved.