-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostMessage-Sample.ps1
More file actions
27 lines (20 loc) · 867 Bytes
/
Copy pathPostMessage-Sample.ps1
File metadata and controls
27 lines (20 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Clear-Host
Set-Location -Path $PSScriptRoot
# Input Parameters
$developerToken = Read-Host 'Enter Your Yammer Developer Token' -MaskInput
$groupId= Read-Host 'Input the Encoded Yammer Group'
$uri="https://www.yammer.com/api/v1/messages.json"
$headers = @{ Authorization=("Bearer " + $developerToken) }
$htmlBody = "This Message is posted using PowerShell"
$body=@{group_id=$groupId;body=$htmlBody}
# 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
}