How To Get The Yammer Messages For A Specific Group ID Using PowerShell

In this blog, you will see how to get the Yammer messages for a specific group ID using PowerShell.

Prerequisites

  • Go to https://www.yammer.com/client_applications and register an app.
  • Once the app is registered, generate a developer token.
 

Copy the below script and paste it in a Notepad. Save the file as MessagesbyGroupID.ps1.

  1. # Input Parameters  
  2. $developerToken = "12240-gSRfasdf***VtnbXYw"  
  3. $groupID="12299137"  
  4. $uri="https://www.yammer.com/api/v1/messages/in_group/"+$groupID+".json"  
  5. $headers = @{ Authorization=("Bearer " + $developerToken) }  
  6.   
  7. # Invoke Web Request  
  8. $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers  
  9.   
  10. Check whether the status code is 200  
  11. if ($webRequest.StatusCode -eq 200) {  
  12.   
  13.     # Converts a JSON-formatted string to a custom object or a hash table.   
  14.     $results = $webRequest.Content | ConvertFrom-Json  
  15.   
  16.     write-host -ForegroundColor Blue "Messages Count: " $results.messages.length  
  17.   
  18.     # Loop through all the messages  
  19.     $results.messages | ForEach-Object {  
  20.         $message = $_   
  21.         # Display the created date and time  
  22.         Write-Host -ForegroundColor Green $message.created_at  
  23.     }  
  24. }  
  25. else {  
  26.     Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status  
  27. }  

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – MessagesbyGroupID.ps1 file location

Run the following command.

  1. >.\MessagesbyGroupID.ps1  

 

Reference

https://developer.yammer.com/docs/messagesin_groupgroup_id

Thus in this blog, you saw how to get the Yammer messages for a specific group ID using PowerShell.