Change Azure active subscription in Powershell and web portal

Change Azure active subscription in Powershell and web portal

If the Azure account has more than one subscription there is possible to switch between different subscriptions on the fly.

In Powershell to have it working there is needed to have subscriptions IDs. First login to your Azure account by command Connect-AzAccount. During that process the command ask to authenticate in the Miscrosoft page and enter the code:

PS> Connect-AzAccount   
WARNING: To sign in, use a web browser to open the page and enter the code BMSJMV9ZG to authenticate.

Account         SubscriptionName                  TenantId                             Environment
-------         ----------------                  --------                             -----------  XX-AZR_XX_XX_Development          xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx AzureCloud

To change the subscription use command Set-AzContext with Subscription ID:

> Set-AzContext 1x1x1x1x-1x1x-1x1x-1x1x-1x1x1x1x1x1x                                
Name                                     Account                                SubscriptionName                      Environment                           TenantId
----                                     -------                                ----------------                      -----------                           --------
XX-AZR_XX_XX_Test (1x1x…                               XX-AZR_XX_XX_Test                      AzureCloud                            yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy

To change subscription in Azure portal go the the main page and in the right corner click on your account name and click “Switch directory” link:

Then at the bottom of the page you can select the subscription you want to work with.

Leave a Reply