Get-AzAccessToken

Get raw access token. When using -ResourceUrl, please make sure the value does match current Azure environment. You may refer to the value of (Get-AzContext).Environment.

Syntax

Get-AzAccessToken
   [-ResourceTypeName <String>]
   [-TenantId <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Get-AzAccessToken
   -ResourceUrl <String>
   [-TenantId <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

Get access token

Examples

Example 1 Get the access token for ARM endpoint

PS C:\> Get-AzAccessToken

Get access token of current account for ResourceManager endpoint

Example 2 Get the access token for Microsoft Graph endpoint

PS C:\> Get-AzAccessToken -ResourceTypeName MSGraph

Get access token of Microsoft Graph endpoint for current account

Example 3 Get the access token for Microsoft Graph endpoint

PS C:\> Get-AzAccessToken -ResourceUrl "https://graph.microsoft.com/"

Get access token of Microsoft Graph endpoint for current account

Parameters

-DefaultProfile

The credentials, account, tenant, and subscription used for communication with Azure.

Type:IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ResourceTypeName

Optional resource type name, supported values: AadGraph, AnalysisServices, Arm, Attestation, Batch, DataLake, KeyVault, MSGraph, OperationalInsights, ResourceManager, Storage, Synapse. Default value is Arm if not specified.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-ResourceUrl

Resource url for that you're requesting token, e.g. 'https://graph.microsoft.com/'.

Type:String
Aliases:Resource, ResourceUri
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-TenantId

Optional Tenant Id. Use tenant id of default context if not specified.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False

Inputs

None

Outputs

PSAccessToken