Created
March 15, 2019 13:22
-
-
Save brettmillerb/69c557f269515ea903364948238a41ab to your computer and use it in GitHub Desktop.
Get-AzCachedAccessToken
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-AzCachedAccessToken { | |
<# | |
.SYNOPSIS | |
Get the Bearer token from the currently set AzContext | |
.DESCRIPTION | |
Get the Bearer token from the currently set AzContext. Retrieves from Get-AzContext | |
.EXAMPLE | |
Get-AzCachedAccesstoken | |
.EXAMPLE | |
Get-AzCachedAccesstoken -Verbose | |
#> | |
[cmdletbinding()] | |
param() | |
$currentAzureContext = Get-AzContext | |
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile) | |
Write-Verbose ("Tenant: {0}" -f $currentAzureContext.Subscription.Name) | |
$token = $profileClient.AcquireAccessToken($currentAzureContext.Tenant.TenantId) | |
$token.AccessToken | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment