In this blog, you will see how to post a message in a 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 PostMessage.ps1.

  1. # Input Parameters
  2. $developerToken = "12240-*****iPR2NWpZVtnbXYw"
  3. $groupID="15653442"
  4. $uri="https://www.yammer.com/api/v1/messages.json"
  5. $headers = @{ Authorization=("Bearer " + $developerToken) }
  6. $body=@{group_id="15653442";body="This message is posted using PowerShell."}
  7. # Invoke Web Request
  8. $webRequest = Invoke-WebRequest –Uri $uri –Method POST -Headers $headers -Body $body
  9. # Check whether the status code is 201 created
  10. if ($webRequest.StatusCode -eq 201) {
  11. write-host -ForegroundColor Green "Message posted successfully."
  12. }
  13. else {
  14. Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
  15. }

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – PostMessage.ps1 file location

Run the following command

  1. >.\PostMessage.ps1

Thus in this blog, you saw how to post a message in Yammer group using PowerShell.