How To Get Announcements From A Specific Yammer Group Using PowerShell

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

  1. # Input Parameters  
  2. $developerToken = "12240-******PR2NWpZVtnbXYw"  
  3. $groupID="15653442"  
  4. $uri="https://www.yammer.com/api/v1/messages/in_group/"+$groupID+".json"  
  5. $headers = @{ Authorization=("Bearer " + $developerToken) }  
  6.   
  7. Function GetAnnouncements($pageNo)  
  8. {  
  9.     # Invoke Web Request  
  10.     $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers  
  11.   
  12.     # Check whether the status code is 200  
  13.     if ($webRequest.StatusCode -eq 200) {  
  14.   
  15.         # Converts a JSON-formatted string to a custom object or a hash table.   
  16.         $results = $webRequest.Content | ConvertFrom-Json          
  17.   
  18.         # Loop through all the messages  
  19.         $results.messages | ForEach-Object {  
  20.             $message = $_   
  21.   
  22.             # Check if the message type is announcement  
  23.             if($message.message_type -eq "announcement")  
  24.             {  
  25.                 # Display the announcement title  
  26.                 Write-Host -ForegroundColor Green $message.title  
  27.             }  
  28.         }  
  29.   
  30.         # Check if there are more items available      
  31.         if($results.more_available)      
  32.         {      
  33.             GetUsers($pageNo+1)      
  34.         }    
  35.     }  
  36.     else {  
  37.         Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status  
  38.     }  
  39. }     
  40.       
  41. # Call the function      
  42. GetAnnouncements(1)   

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"  

folderlocation – GetAnnouncements.ps1 file location

Run the following command,

  1. >.\GetAnnouncements.ps1  

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