In this blog, you will see how to get a list of groups for a current user in Yammer 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 GetGroups.ps1.

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

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetGroups.ps1 file location

Run the following command:

  1. >.\GetGroups.ps1

Thus in this blog, you saw how to get the list of groups for a current user in Yammer using PowerShell.