Last active
November 27, 2025 02:56
-
-
Save gscales/899093311585eab39edca2c37da72ef7 to your computer and use it in GitHub Desktop.
Authentication in Exchange Admin API using Graph MSAL
This file contains hidden or 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
| Import-Module Microsoft.Graph.Authentication -ErrorAction Stop | |
| $graphModule = Get-Module Microsoft.Graph.Authentication | |
| $msalDll = Get-ChildItem -Path $graphModule.ModuleBase -Filter "Microsoft.Identity.Client.dll" -Recurse | Select-Object -First 1 | |
| if ($msalDll) { | |
| Add-Type -Path $msalDll.FullName | |
| Write-Host "Microsoft.Identity.Client loaded successfully from: $($msalDll.FullName)" | |
| } | |
| else { | |
| Write-Error "Microsoft.Identity.Client.dll not found" | |
| } | |
| $clientId = "a7bd291b-c836-479b-a03e-xxxxxxx" | |
| $tenantId = "13af9f3c-b494-4795-bb19-xxxxx" | |
| $app = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create($clientId).WithDefaultRedirectUri().WithTenantId($tenantId).Build() | |
| $scopes = [System.Collections.Generic.List[string]]@("https://outlook.office365.com/.default") | |
| $AccessToken = ($app.AcquireTokenInteractive($scopes).ExecuteAsync().Result).AccessToken |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment