Created
June 24, 2020 01:46
-
-
Save chrismckelt/509e8a2a0adaef4d6f6751d09dd0413f to your computer and use it in GitHub Desktop.
PowerShell Get-AccessToken
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
function Get-AccessToken { | |
$context = Get-AzContext | |
$myprofile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
$profileClient = New-Object -TypeName Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient -ArgumentList ($myprofile) | |
$token = $profileClient.AcquireAccessToken($context.Subscription.TenantId) | |
return $token.AccessToken | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
CLI
az account get-access-token --query 'accessToken' -o tsv