Loading…

READY TO ROCK?

Quick Tip: Getting the Azure RM Profile Token

There are multiple ways to connect to Azure to get information or to do tasks. Azure supports Rest API calls to do many tasks. For REST API calls or for scenarios where you will need your Azure RM Profile token you can run the following commands to get the Azure token. The example below also shows you how to use this token and get information from Azure over REST API calls.

Powershell Code

Import-Module AzureRM.Profile
$azureRMProfile = [Microsoft.Azure.Commands.common.Authentication.Abstractions.AzureRMProfileProvider]::Instance.Profile
$currentAzureContext = Get-AzureRMContext
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azureRMProfile)
$token = ($profileClient.AcquireAccessToken($currentAzureContext.Subscription.TenantId)).accesstoken
Write-host "The token is:" $token # Comment this line if you do not want the token to be visible

The above powershell code can give you the Azure RM token that can be used in a Rest API call to Azure. The below Example demonstrate using this token value to connect to Azure and fetch