forked from bwya77/GraphAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph_Get_Teams_Channel_Messages_Top3.ps1
22 lines (17 loc) · 1.25 KB
/
Graph_Get_Teams_Channel_Messages_Top3.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#Permissions needed: Group.Read.All,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 for the General chat
$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
#Grab newest 3 messages from channel
$apiUrl = "https://graph.microsoft.com/beta/teams/$ManagementTeamID/channels/$ChannelID/messages?`$top=3"
$Data = Invoke-RestMethod -Headers @{Authorization = "Bearer $($Tokenresponse.access_token)"} -Uri $apiUrl -Method Get
$Messages = ($Data | Select-Object Value).Value
$Messages | Select-Object @{Name = 'Message'; Expression = {(($_).body).content}}, @{Name = 'From'; Expression = {((($_).from).user).displayName}} | Format-List