How to Set a Default Subscription on Azure Using PowerShell

In this blog post, we will discuss how to set a default subscription on Azure using PowerShell.

Before we dive into the details of setting a default subscription, let’s first understand what a subscription is in Azure. A subscription is a logical container for resources that allows users to access Azure services. It provides a unique identifier for billing and management purposes. When you create an Azure account, you are given a subscription that you can use to access Azure services.

Install Azure PowerShell

The first step is to install the Azure PowerShell module. To do this, open PowerShell as an administrator and run the following command:

Install-Module -Name Az -AllowClobber

This command will install the latest version of the Azure PowerShell module on your system.

Connect to your Azure account

Once you have installed the Azure PowerShell module, you need to connect to your Azure account. To do this, run the following command:

Connect-AzAccount

This command will prompt you to enter your Azure credentials. Enter your username and password to connect to your Azure account.

Set the default subscription

To set the default subscription, run the following command:

Set-AzContext -SubscriptionId <SubscriptionId>

Replace <SubscriptionId> with the ID of the subscription, you want to set as default. You can get the subscription ID by running the following command:

Get-AzSubscription

This command will list all the subscriptions associated with your Azure account, along with their IDs.

Verify the default subscription

To verify that you have set the default subscription correctly, run the following command:

Get-AzContext

This command will display the details of the current context, including the default subscription.

That’s it! You have successfully set the default subscription on Azure using PowerShell. From now on, all Azure PowerShell commands will be executed against the default subscription you have set.


Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.