-
Notifications
You must be signed in to change notification settings - Fork 0
/
UndoChatRemovals.ps1
54 lines (37 loc) · 1.37 KB
/
UndoChatRemovals.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
Param(
[Parameter(Mandatory=$true)]
[string] $CsvPath,
[Parameter(Mandatory=$true)]
[string] $TenantId,
[Parameter(Mandatory=$true)]
[string] $AppId,
[Parameter(Mandatory=$true)]
[string] $AppSecret
)
Import-Module MSAL.PS
$RemovalInstanceList = Import-Csv -Path $CsvPath
Function Connect-TeamsAPI {
If ($Token.ExpiresOn.LocalDateTime -gt (Get-Date).AddMinutes(15)) {
Return
}
Else {
Write-Host 'Refreshing Teams API access token...'
}
$AppSecretString = ConvertTo-SecureString -String $AppSecret -AsPlainText -Force
$global:Token = Get-MsalToken -ClientId $AppId -ClientSecret $AppSecretString -TenantId $TenantId -ForceRefresh
$global:Headers = @{Authorization = "Bearer $($Token.AccessToken)"}
}
ForEach ($RemovalInstance in $RemovalInstanceList) {
Connect-TeamsAPI
$Body = @{
"@odata.type" = "#microsoft.graph.aadUserConversationMember"
"User@odata.bind" = "https://graph.microsoft.com/beta/users/$($RemovalInstance.RemovedMemberId)"
VisibleHistoryStartDateTime = "0001-01-01T00:00:00Z"
Roles = @(
"owner"
)
}
$Body = $Body | ConvertTo-Json
$Response = Invoke-WebRequest -Uri "https://graph.microsoft.com/beta/chats/$($RemovalInstance.ChatId)/members" -Headers $Headers -ContentType 'application/json' -Method POST -Body $Body -Verbose
$ResponseJson = ($Response | ConvertFrom-Json)
}