-
Notifications
You must be signed in to change notification settings - Fork 219
/
Teams_utils.ps1
64 lines (53 loc) · 2.3 KB
/
Teams_utils.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Gets Teams service information
# Oct 16th 2020
function Get-TeamsUserSettings
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "https://api.spaces.skype.com" -ClientId "1fec8e78-bce4-4aaf-ab1b-5451cc387264"
Invoke-RestMethod -UseBasicParsing -Method Post -Uri "https://teams.microsoft.com/api/authsvc/v1.0/authz" -Headers @{"Authorization"="Bearer $AccessToken"}
}
}
# Gets Teams recipients info
# May 11th 2021
function Get-TeamsRecipients
{
[cmdletbinding()]
Param(
[Parameter(Mandatory=$False)]
[String]$AccessToken,
[Parameter(Mandatory=$True)]
[String[]]$Recipients
)
Process
{
# Get from cache if not provided
$AccessToken = Get-AccessTokenFromCache -AccessToken $AccessToken -Resource "https://api.spaces.skype.com" -ClientId "1fec8e78-bce4-4aaf-ab1b-5451cc387264"
# Must be a proper array, so add element if only one provided
if($Recipients.Count -eq 1)
{
$Recipients += ""
}
# Get the settings
$teamsSettings = Get-TeamsUserSettings -AccessToken $AccessToken
$chatService = $teamsSettings.regionGtms.chatService
$apiUrl = $teamsSettings.regionGtms.middleTier
$skypeToken = $teamsSettings.tokens.SkypeToken
# Construct the headers
$headers = @{
"Authorization" = "Bearer $AccessToken"
"User-Agent" = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Teams/1.3.00.24755 Chrome/69.0.3497.128 Electron/4.2.12 Safari/537.36"
"Authentication" = "skypetoken=$skypeToken"
"x-ms-client-version" = "27/1.0.0.2020101241"
}
$recipientInfo = Invoke-RestMethod -UseBasicParsing -Method Post -Uri "$apiUrl/beta/users/fetch?isMailAddress=true&canBeSmtpAddress=false&enableGuest=true&includeIBBarredUsers=true&skypeTeamsInfo=true" -Headers $headers -Body ([String[]]$Recipients|ConvertTo-Json) -ContentType "application/json"
$msgRecipients = $recipientInfo.Value
return $msgRecipients
}
}