In this Azure PowerShell article, we will discuss the syntax and usage of the Set-AzContext PowerShell command. How to set Az contexts using Azure PowerShell command Set-AzContext.
Table of Contents
Set-AzContext
The Set-AzContext PowerShell command can help you to set the subscription, tenant, and environments for different PowerShell commands to be used in your current PowerShell session.
Syntax of Set-AzContext
Below is the syntax of the Set-AzContext PowerShell command.
Set-AzContextSet-AzContext [-Subscription] <String>Set-AzContext
[-Tenant <String>]
[-Subscription] <String>Set-AzContext
-Tenant <String>Let’s discuss a few examples of how to use the Set-AzContext PowerShell command.
Set-AzContext example
Example-1:
You can execute the PowerShell command below to set the specified subscription context.
Set-AzContext -Subscription '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'After executing the above PowerShell command, I got the below-expected output
PS C:\WINDOWS\system32> Set-AzContext -Subscription '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'
Name Account SubscriptionName Environment TenantId
---- ------- ---------------- ----------- --------
Visual Studio Enterprise (1cdf4300-de... fewlines4biju@hotmail.com Visual Studio Enterprise AzureCloud 5d9d690a-0310-474d-ae8b-4...
You can check the same output in the below screenshot.

Example-2
You can also use the Subscription name parameter and the Set-AzContext PowerShell command.
Set-AzContext -SubscriptionName 'Visual Studio Enterprise'After executing the above command, we got the expected output as shown below.

Example-3
You can also use the Tenant parameter along with the Set-AzContext PowerShell command.
Set-AzContext -Tenant '5d9d690a-0310-474d-ae8b-42df2d549228'After executing the above command, I got the expected output below

You may also like following the articles below
- The ‘Set-AzContext’ command was found in the module ‘Az.Accounts’ but the module could not be loaded.
- Set-AzContext : Please provide a valid tenant or a valid subscription.
Wrapping Up
In this Azure PowerShell article, we discussed the syntax and usage of the Set-AzContext PowerShell command with examples of how to use this command.

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, 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.
