Thursday, 10 October 2024

Connect to EXO Module using Client Id & Secret - Graph API


$ClientID       = "xxxxxxxxxxxxxxxx"
$TenantID      = "xxxxxxxxxxxxxxxx"
$ClientSecret = "xxxxxxxxxxxxxxxx"
$TokenEndpoint = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"

$body = @{
            grant_type    = "client_credentials"
            scope         = "https://outlook.office365.com/.default"
            client_id     = $clientId
            client_secret = $clientSecret
}

$TokenResponse = Invoke-RestMethod -Method Post -Uri $tokenEndpoint -ContentType "application/x-www-form-urlencoded" -Body $body


Write-Host "Connecting to Exchange Online"
 
$AccessToken = $tokenResponse.access_token
 
Write-Host "Access token obtained successfully."
 
# Connect to Exchange Online using the obtained access token
 
Connect-ExchangeOnline -AppId $clientId -AccessToken $accessToken -Organization $tenantId -ShowBanner:$false




--------------------------------- End --------------------------------- 
 

No comments:

Post a Comment