In this Azure PowerShell article, we will discuss the syntax and usage of the Get-AzContext Azure PowerShell cmdlet with examples.
Table of Contents
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 below Azure PowerShell cmdlet that can help you to 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 as below

Example-2:
You can execute the below Azure PowerShell cmdlet to list down all the available contexts.
Get-AzContext -ListAvailable
In my case, 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.

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 !!!

I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.