Forked from ChrFrohn/ConnectToTeams-ServicePrincipal.ps1
Created
March 15, 2023 19:43
-
-
Save mozziemozz/62337a4cc46923e5b285794ca6d173ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ClientSecret = "" | |
$ApplicationID = "" | |
$TenantID = "" | |
$graphtokenBody = @{ | |
Grant_Type = "client_credentials" | |
Scope = "https://graph.microsoft.com/.default" | |
Client_Id = $ApplicationID | |
Client_Secret = $ClientSecret | |
} | |
$graphToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body $graphtokenBody | Select-Object -ExpandProperty Access_Token | |
$teamstokenBody = @{ | |
Grant_Type = "client_credentials" | |
Scope = "48ac35b8-9aa8-4d74-927d-1f4a14a0b239/.default" | |
Client_Id = $ApplicationID | |
Client_Secret = $ClientSecret | |
} | |
$teamsToken = Invoke-RestMethod -Uri "https://login.microsoftonline.com/$TenantID/oauth2/v2.0/token" -Method POST -Body $teamstokenBody | Select-Object -ExpandProperty Access_Token | |
Connect-MicrosoftTeams -AccessTokens @("$graphToken", "$teamsToken") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment