Jan 02 2018 10:15 AM - edited Jan 02 2018 10:59 AM
If you need to delete older messages from a particular group, there's no built-in way to do that. However, like most things, you can use the REST API as well as PowerShell to accomplish this. Two uses I've seen for this functionality is to meet maximum retention policies (e.g. we need to remove all content older than 12 months), as well as some groups are so prolific that old information clogs search results. Whatever your need, here's the script to accomplish this.
First, like all the other scripts I've supplied, you need to get a permanent token. Once you have that, copy this script and save it to Notepad, and give it a name ending in .ps1 (rather than .txt). Edit the file to have the correct token as well as directories, date of last wanted message, and group ID. Execute the script by type cmd (enter), then powershell (enter), then .\<the name of your file>.
#This section is for you to customize your script for your environment #If the directories don't exist or the token is wrong, this won't work. #This has to be YOUR token $token = "Token" #This is the directory where your messages.csv file is stored (from export) $SourceDir = "C:\Data\DeleteOld" #This is the directory where the csv file is going to be created $OutputDir = "C:\Data\DeleteOld\Output" #Update the date here to determine what is the date at which it will start deleting messages $TheEnd = (Get-Date 2017-07-01).toString("yyyy-MM-dd") #Set the target group $groupid = 123456789 #================================== #This section you shouldn't need to modify $Headers = @{ "Accept" = "*/*" "Authorization" = "Bearer "+$token "accept-encoding" = "gzip" "content-type"="application/json" "content-length" = "2" }
#import Message ID's that need evaluated. import-csv $SourceDir\Messages.csv | where {$_.created_at -le $TheEnd -and $_.group_id -eq $groupid} |Select id, created_at, group_id | export-csv -path $OutputDir\Output.csv $messages = import-csv $OutputDir\Output.csv $messages = $messages.id #loop through all Message ID's foreach ($message in $messages){ $uri = "https://www.yammer.com/api/v1/messages/$message" (Invoke-WebRequest -Uri $uri -Method Delete -Headers $Headers).content }
Please post below if you find the script useful.
Jun 06 2020 04:40 PM
@Tom Kretzmerthanks you for your post!
I have a question: How do I get the message.csv file? I understand that I should run another script to get all the messages from the group from which I want to delete the messages. Do you have that script? Thank you!
Jan 21 2021 07:51 AM
Thanks for your post, but I would like to know how I make the messages.csv file please.
Very thanks in advance for your answer.
Dec 12 2022 02:20 PM - edited Dec 12 2022 02:55 PM
I'm about to get into this myself...I'm trying to export data from yammer to CSV, maybe the list of messages will be there? Trying now.