Created
March 11, 2026 16:56
-
-
Save joerodgers/2913b83847414332657f0ccdf093a71c to your computer and use it in GitHub Desktop.
Uses Microsoft.Identity.Client assembly loaded via the "Microsoft.PowerApps.Administration.PowerShell" module to generate an Entra access token
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
| #requires -modules "Microsoft.PowerApps.Administration.PowerShell" | |
| $clientId = $env:CDX_CLIENTID | |
| $tenantId = $env:CDX_TENANTID | |
| [string[]]$scopes = "https://api.powerplatform.com/.default", "openid", "profile offline_access" | |
| $pca = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create($clientId).WithAuthority( "https://login.microsoftonline.com/$tenantId", $true). | |
| WithRedirectUri( "http://localhost" ). | |
| Build() | |
| $task = $pca.AcquireTokenInteractive($scopes).WithUseEmbeddedWebView($false).ExecuteAsync() | |
| while (-not $task.AsyncWaitHandle.WaitOne(200)) { } | |
| $task.GetAwaiter().GetResult() | |
| $authResult.AccessToken | Set-Clipboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment