In this Azure PowerShell article, we will discuss the syntax and usage of the Set-AzContext PowerShell command with examples of how to use this command.
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
Below is the syntax of the Set-AzContext PowerShell command.
Set-AzContext
Set-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.
Example-1:
You can execute the below PowerShell command to set the context for the specified subscription.
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 along with 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 below articles
- 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.