How To Get All Of The Yammer Groups Using PowerShell

In this blog, you will see how to get all the Yammer groups using PowerShell.

In this blog, you will see how to get all of the Yammer groups 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 Groups.ps1.

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

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

folderlocation – Groups.ps1 file location.

Run the following command.

  1. >.\Groups.ps1  

Thus in this blog, you saw how to how to get all the Yammer groups using PowerShell.