How To Get All Yammer Users From A Specific Group Using PowerShell

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