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.
- # Input Parameters
- $developerToken = "12240-*****iPR2NWpZVtnbXYw"
- $groupID="15653442"
- $uri="https://www.yammer.com/api/v1/messages.json"
- $headers = @{ Authorization=("Bearer " + $developerToken) }
- $body=@{group_id="15653442";body="This message is posted using PowerShell."}
-
- # Invoke Web Request
- $webRequest = Invoke-WebRequest –Uri $uri –Method POST -Headers $headers -Body $body
-
- # Check whether the status code is 201 created
- if ($webRequest.StatusCode -eq 201) {
- write-host -ForegroundColor Green "Message posted successfully."
- }
- else {
- Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
- }
Open PowerShell window and run the following command.
folderlocation – PostMessage.ps1 file location
Run the following command
Thus in this blog, you saw how to post a message in Yammer group using PowerShell.