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.
- # Input Parameters
- $developerToken = "461-yyxH31YOkutfuKoWUEmWPg"
- $groupID="8010451"
- $headers = @{ Authorization=("Bearer " + $developerToken) }
- $count=0;
-
- Function GetUsers($pageNo)
- {
- #page parameter- Programmatically paginate through the users in the network. 50 users will be shown per page.
- $uri="https://www.yammer.com/api/v1/users/in_group/" + $groupID +".json?page=" + $pageNo
-
- # Invoke Web Request
- $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
-
- # Check whether the status code is 200
- if ($webRequest.StatusCode -eq 200) {
-
- # Converts a JSON-formatted string to a custom object or a hash table.
- $results = $webRequest.Content | ConvertFrom-Json
-
- $count=$count+$results.users.length
-
- # Loop through all the users
- $results.users | ForEach-Object {
- $user = $_
- # Display all the user details
- Write-Host -ForegroundColor Green "Full Name: " $user.full_name " - Email: "$user.email
-
- }
-
- # Check if there are more items available
- if($results.more_available)
- {
- GetUsers($pageNo+1)
- }
- else
- {
- write-host -ForegroundColor Magenta "Total number of users in this group: " $count
- }
- }
- else {
- Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
- }
- }
-
- # Call the function
- GetUsers(1)
Open PowerShell window and run the following command.
folderlocation – GetUsers.ps1 file location
Run the following command.
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.