Skip to content

Instantly share code, notes, and snippets.

@chrismckelt
Created June 24, 2020 01:46
Show Gist options
  • Save chrismckelt/509e8a2a0adaef4d6f6751d09dd0413f to your computer and use it in GitHub Desktop.
Save chrismckelt/509e8a2a0adaef4d6f6751d09dd0413f to your computer and use it in GitHub Desktop.
PowerShell Get-AccessToken
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
}
@chrismckelt
Copy link
Author

CLI

az account get-access-token --query 'accessToken' -o tsv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment