forked from bwya77/GraphAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph_Post_Teams_Message.ps1
31 lines (21 loc) · 1.07 KB
/
Graph_Post_Teams_Message.ps1
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
#Permissions needed: Group.ReadWrite.All
#Getting all Groups
$apiUrl = "https://graph.microsoft.com/beta/groups/"
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method Get
$Groups = ($Data | Select-Object Value).Value
#Get ID of management team group
$ManagementTeamID = ($Groups | Where-Object {$_.displayname -eq "Management"}).id
#List the channels in the group, grab the ID
$apiUrl = "https://graph.microsoft.com/beta/groups/$ManagementTeamID/Channels"
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method Get
$Channels = ($Data | Select-Object Value).Value | Where-Object {$_.displayName -eq "General"}
$ChannelID = ($Channels).ID
$apiUrl = "https://graph.microsoft.com/beta/teams/$ManagementTeamID/channels/$ChannelID/messages"
$body = @"
{
"body": {
"content": "Hello World"
}
}
"@
Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Body $Body -Method Post -ContentType 'application/json'