In this blog, you will see how to get announcements from a specific Yammer group 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 GetAnnouncements.ps1.

  1. # Input Parameters
  2. $developerToken = "12240-******PR2NWpZVtnbXYw"
  3. $groupID="15653442"
  4. $uri="https://www.yammer.com/api/v1/messages/in_group/"+$groupID+".json"
  5. $headers = @{ Authorization=("Bearer " + $developerToken) }
  6. Function GetAnnouncements($pageNo)
  7. {
  8. # Invoke Web Request
  9. $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
  10. # Check whether the status code is 200
  11. if ($webRequest.StatusCode -eq 200) {
  12. # Converts a JSON-formatted string to a custom object or a hash table.
  13. $results = $webRequest.Content | ConvertFrom-Json
  14. # Loop through all the messages
  15. $results.messages | ForEach-Object {
  16. $message = $_
  17. # Check if the message type is announcement
  18. if($message.message_type -eq "announcement")
  19. {
  20. # Display the announcement title
  21. Write-Host -ForegroundColor Green $message.title
  22. }
  23. }
  24. # Check if there are more items available
  25. if($results.more_available)
  26. {
  27. GetUsers($pageNo+1)
  28. }
  29. }
  30. else {
  31. Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
  32. }
  33. }
  34. # Call the function
  35. GetAnnouncements(1)

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetAnnouncements.ps1 file location

Run the following command,

  1. >.\GetAnnouncements.ps1

Thus in this blog, you saw how to get announcements from a specific Yammer group using PowerShell.