Get-AzContext

This Azure PowerShell article will discuss the syntax and usage of the Get-AzContext Azure PowerShell cmdlet with examples.

Get-AzContext

Get-AzContext is an excellent Azure PowerShell cmdlet that can help you to retrieve the metadata details i.e., Azure subscription, AAD account, AD tenant, and the Azure environment details, TokenCache, VersionProfile, etc., that are required to authenticate the Azure Resource Manager request.

Syntax of Get-AzContext

Below are the syntaxes of the Get-AzContext Azure PowerShell cmdlet.

Get-AzContext
Get-AzContext
 [[-Name] <String>]
 [<CommonParameters>]
Get-AzContext
 [-ListAvailable] [<CommonParameters>]

Example-1:

Execute the Azure PowerShell cmdlet below to help you get the current context.

Connect-AzAccount
Get-AzContext

After executing the above Azure PowerShell cmdlet, I got the below output.

PS C:\Users\Bijay> Connect-AzAccount
Get-AzContext

Account                   SubscriptionName         TenantId                           
-------                   ----------------         --------                           
fewlines4biju@hotmail.com Visual Studio Enterprise 5d9d690a-0310-684d-ae9b-42df2d78...

Name               : Visual Studio Enterprise (1cdf4300-dtt5-4518-8c8c-feaa78a8cbd7) 
                     - 5d9d690a-0310-567d-ae9b-42df2d889278 - 
                     fewlines4biju@hotmail.com
Account            : fewlines4biju@hotmail.com
Environment        : AzureCloud
Subscription       : 1cdf4300-dtt5-4518-8c8c-feaa78a8cbd7
Tenant             : 5d9d690a-0310-567d-ae9b-42df2d889278
TokenCache         : 
VersionProfile     : 
ExtendedProperties : {}

You can see that here below

Get-AzContext

Example-2:

You can execute the Azure PowerShell cmdlet below to list all the available contexts.

Get-AzContext -ListAvailable

There is only one context, so I got the below output. But if you have more than one context, you will get lists of all the contexts.

get azcontext

You may also like following the articles below

Wrapping Up

In this Azure PowerShell article, we have discussed the syntax and usage of the Get-AzContext Azure PowerShell cmdlet with examples. Thanks for reading this article !!!