Get-AzAccessToken
Get secure 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.
Note
For security purposes, the default output type has been changed from a plain text String to SecureString. For more information, see Protect secrets in Azure PowerShell.
Syntax
KnownResourceTypeName (Default)
Get-AzAccessToken
[-ResourceTypeName <String>]
[-TenantId <String>]
[-AsSecureString]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
ResourceUrl
Get-AzAccessToken
-ResourceUrl <String>
[-TenantId <String>]
[-AsSecureString]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
Get secure access token
Examples
Example 1 Get the access token for ARM endpoint
Get-AzAccessToken -AsSecureString
Get access token of current account for ResourceManager endpoint
Example 2 Get the access token for Microsoft Graph endpoint
Get-AzAccessToken -AsSecureString -ResourceTypeName MSGraph
Get access token of Microsoft Graph endpoint for current account
Example 3 Get the access token for Microsoft Graph endpoint
Get-AzAccessToken -AsSecureString -ResourceUrl "https://graph.microsoft.com/"
Get access token of Microsoft Graph endpoint for current account
Parameters
-AsSecureString
The parameter is no longer used but kept for backward compatibility. No matter AsSecureString is specified, the output token is a SecureString.
Parameter properties
| Type: | SwitchParameter |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-ResourceTypeName
Optional resource type name, supported values: AadGraph, AnalysisServices, AppConfiguration, Arm, Attestation, Batch, CommunicationEmail, DataLake, KeyVault, MSGraph, OperationalInsights, ResourceManager, Storage, Synapse. Default value is Arm if not specified.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
KnownResourceTypeName
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-ResourceUrl
Resource url for that you're requesting token, e.g. 'https://graph.microsoft.com/'.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | Resource, ResourceUri |
Parameter sets
ResourceUrl
| Position: | Named |
| Mandatory: | True |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
-TenantId
Optional Tenant Id. Use tenant id of default context if not specified.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
(All)
| Position: | Named |
| Mandatory: | False |
| Value from pipeline: | False |
| Value from pipeline by property name: | False |
| Value from remaining arguments: | False |
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.