Last active
September 26, 2017 14:42
-
-
Save arsenvlad/2db9e556fe5ddda909ec1ef933cb30a5 to your computer and use it in GitHub Desktop.
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
# Based on code from https://gallery.technet.microsoft.com/scriptcenter/Easily-obtain-AccessToken-3ba6e593 | |
# Assumes AzureRm.Profile module is improted and is version 3 or newer | |
$azureRmProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile | |
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRmProfile) | |
$currentAzureRmContext = Get-AzureRmContext | |
$token = $profileClient.AcquireAccessToken($currentAzureRmContext.Subscription.TenantId) | |
$accessToken = $token.AccessToken | |
$accessToken | |
# Invoke Azure Resource Manager REST API | |
$headers = @{ Authorization = "Bearer $accessToken" } | |
# List subscriptions | |
Invoke-WebRequest -uri "https://management.azure.com/subscriptions?api-version=2014-04-01" -Headers $headers -UseBasicParsing | ConvertFrom-Json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment