In this blog, you will see how to get all Yammer messages in a specific thread 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 MessagesinThread.ps1.

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

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – MessagesinThread.ps1 file location

Run the following command.

  1. >.\MessagesinThread.ps1

Thus, in this blog, you saw how to get all Yammer messages in a specific thread using PowerShell.