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

  1. # Input Parameters
  2. $developerToken = "461-yyxH31YOkutfuKoWUEmWPg"
  3. $groupID="8010451"
  4. $headers = @{ Authorization=("Bearer " + $developerToken) }
  5. $count=0;
  6. Function GetUsers($pageNo)
  7. {
  8. #page parameter- Programmatically paginate through the users in the network. 50 users will be shown per page.
  9. $uri="https://www.yammer.com/api/v1/users/in_group/" + $groupID +".json?page=" + $pageNo
  10. # Invoke Web Request
  11. $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
  12. # Check whether the status code is 200
  13. if ($webRequest.StatusCode -eq 200) {
  14. # Converts a JSON-formatted string to a custom object or a hash table.
  15. $results = $webRequest.Content | ConvertFrom-Json
  16. $count=$count+$results.users.length
  17. # Loop through all the users
  18. $results.users | ForEach-Object {
  19. $user = $_
  20. # Display all the user details
  21. Write-Host -ForegroundColor Green "Full Name: " $user.full_name " - Email: "$user.email
  22. }
  23. # Check if there are more items available
  24. if($results.more_available)
  25. {
  26. GetUsers($pageNo+1)
  27. }
  28. else
  29. {
  30. write-host -ForegroundColor Magenta "Total number of users in this group: " $count
  31. }
  32. }
  33. else {
  34. Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
  35. }
  36. }
  37. # Call the function
  38. GetUsers(1)
Open PowerShell window and run the following command.
  1. >cd "<folderlocation>"

folderlocation – GetUsers.ps1 file location

Run the following command.

  1. >.\GetUsers.ps1

Reference

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

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