How to Set an Azure Subscription for Default Login in PowerShell

Table of Contents

Name                              Id                      TenantId                     State  
----                              --                      --------                     -----  
Azure Active Directory            10376480-f866-4c43-bbe3 615dc844-35d3-40c2-9db4-xxxx Enabled
Azure Active Directory            94aacba4-9afb-4c3e-9e7b 615dc844-35d3-40c2-9db4-xxxx Enabled
AD04                              c4909c7e-5dc3-43c7-9911 615dc844-35d3-40c2-9db4-xxxx Enabled
RB.60-66                          3177f05d-9d74-4995-abf8 615dc844-35d3-40c2-9db4-xxxx Enabled
RB.05.08                          b319d331-f43b-4347-903d 615dc844-35d3-40c2-9db4-xxxx Enabled
RB.09.12                          633c1a7c-95b3-4b76-a18b 615dc844-35d3-40c2-9db4-xxxx Enabled
RB.37.42                          ea90ff0f-913a-4b6e-809c 615dc844-35d3-40c2-9db4-xxxx Enabled
RB.70.76                          7a09c8e3-6737-4846-9eb5 615dc844-35d3-40c2-9db4-xxxx Enabled

In some cases, your Azure tenant has multiple Azure subscriptions. Every time, when you sign-in into Microsoft Azure using PowerShell, you would get this warning: WARNING: TenantId '615dc844-35d3-40c2-9db4-0439991ec82e' contains more than one active subscription. First one will be selected for further use. To select another subscription, use Set-AzContext. To override which subscription Connect-AzAccount selects by default, use `Update-AzConfig -DefaultSubscriptionForLogin 00000000-0000-0000-0000-000000000000`. Go to https://go.microsoft.com/fwlink/?linkid=2200610 for more information.

Set your Azure default Subscription

You want to set a subscription by default every time you sin-in into Azure using PowerShell.

1. Login into Microsoft Azure using PowerShell using Connect-AzAccount command.

Connect-AzAccount

2. Get the list of the subscriptions in your tenant by name and id. Write down the subscription name or id of the one you want to set to be default subscription.

Get-AzSubscription | Select Name, Id
Name                                        Id
----                                        --
Access to Azure Active Directory            10376480-f866-4c43-bbe3-3cdeb8ebf6b5
Access to Azure Active Directory            11e4abe9-6f88-4d18-97a0-8bf115fb0796
Access to Azure Active Directory            931dc0f7-2125-469a-9830-8ba63bcf6aff
AD09                                        36a4f20e-110e-44f9-ac0e-67d43bc691a7
RB.110.116                                  9511a764-5f67-4619-82b8-48f1e9190e39
RB.31.36                                    5f0a10be-14e3-4720-af5d-bd09c8b0ae65
RB.90.96                                    3c78f1a9-f55d-4c28-8331-f9d99258ed02

3. Run the following command to set a subscription to the default on when login.

Update-AzConfig -DefaultSubscriptionForLogin "Name of subscription or Subcription Id"
Key                         Value                                Applies To Scope       
---                         -----                                ---------- -----       
DefaultSubscriptionForLogin bbf658dc-xxxx-4f6a-b2bc-7c379632c9b7 Az         CurrentUser 

4. Disconnect from Azure PowerShell the reconnect to verify it works.

PS C:\> Disconnect-AzAccount
PS C:\> Connect-AzAccount

Account            SubscriptionName TenantId                             Environment
-------            ---------------- --------                             -----------
[email protected] AD09             36a4f20e-110e-xxxx-ac0e-67d43bc691a7 AzureCloud

Leave a Comment

Required fields are marked *