To change Azure subscription in PowerShell, we can simply use the Select-AZSubscription Azure PowerShell cmdlet. It’s really easy to use. Well, let’s discuss how to change Azure subscriptions using PowerShell. As part of this topic, we will discuss the Select-AZSubscription Azure PowerShell cmdlet and its syntax with examples of how to use this command.
Select-AZSubscription
Select-AZSubscription is an excellent Azure PowerShell cmdlet that can be used to change the Azure subscription.
Let’s discuss the syntax of the Select-AZSubscription Azure PowerShell cmdlet and Examples that will give you enough idea to change your Azure subscription with PowerShell.
Syntax-1
You can change or set the Azure subscription with the help of the Subscription Name parameter.
Select-AzSubscription -SubscriptionName 'The name of your subscription'
Example
Below is an example where Visual Studio Enterprise is the name of my Azure subscription
Select-AzSubscription -SubscriptionName 'Visual Studio Enterprise'
Once you execute the above Azure PowerShell cmdlet, you will get the output like the one below. Check out the screenshot below.
PS C:\WINDOWS\system32> Select-AzSubscription -SubscriptionName 'Visual Studio Enterprise'
Name Account Subscriptio Environmen TenantId
nName t
---- ------- ----------- ---------- --------
Visual Studio Enterprise (1cdf4300-de... fewlines... Visual S... AzureCloud 5d9d690...
Syntax-2
You can also use the Subscription ID as a parameter to change the Azure subscription.
Select-AzSubscription -SubscriptionId 'Your Azure Subscription Id'
Example
1cdf4300-xxxx-4518-6c6c-xxxxxxxxxxxx is my Azure subscription ID.
Select-AzSubscription -SubscriptionId '1cdf4300-dee5-4518-9c9c-feaa72a5cbd1'
Once you execute the above Azure PowerShell cmdlet, you will get the same output as below. Check out the screenshot below.
Read: How to get tenant ID in Azure using PowerShell
Syntax-3
Another syntax is to use Azure TenantID to change Azure subscription
Select-AzSubscription -Tenant 'your tenantId'
Example
5d9d690a-0310-474d-xxxx-xxxxxxxxxxxxx is the tenant Id for me.
Select-AzSubscription -Tenant '5d9d690a-0310-474d-xxxx-xxxxxxxxxxxxx'
If you will execute the above Azure PowerShell cmd, you will get the execute as below
When you have more than one active Azure subscription, you can even use Set-AzContext to change the other Azure subscription.
You may also like following the articles below
Final Words
Well, it’s simple, and we discussed How to change Azure subscription using PowerShell using Select-AZSubscription Azure PowerShell cmdlet.
I am Rajkishore, and I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machine, 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.