Home
%3CLINGO-SUB%20id%3D%22lingo-sub-276696%22%20slang%3D%22en-US%22%3EPowerShell%20Basics%3A%20Getting%20the%20right%20Azure%20Subscription%20in%20Azure%20Cloud%20Shell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-276696%22%20slang%3D%22en-US%22%3E%3CP%3EIf%20you%20have%20multiple%20Microsoft%20Azure%20subscriptions%2C%20it%20can%20be%20challenging%20to%20keep%20track%20of%20them%20all.%20So%20PowerShell%20to%20the%20rescue!%20With%20the%20use%20of%20Azure%20PowerShell%20commands%20installed%20Azure%20Cloud%20Shell%2C%20I%E2%80%99ll%20show%20you%20how%20to%20view%20your%20subscriptions%2C%20and%20change%20to%20different%20subscriptions%20available%20to%20you.%20From%20there%2C%20you%20can%20build%20resources%20in%20Azure%20using%20the%20default%20subscription.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWant%20to%20follow%20along%20in%20Azure%20Cloud%20Shell%3F%20Create%20a%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FAA309ae%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Efree%20trial%20account%3C%2FA%3E%20here%20and%20then%20browse%20to%20%3CA%20href%3D%22https%3A%2F%2Faka.ms%2FAA2zwvj%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Eshell.azure.com%3C%2FA%3E%20to%20begin.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20let%E2%80%99s%20list%20out%20all%20of%20the%20Azure%20subscriptions%20you%20have.%20This%20will%20provide%20you%20the%20names%2C%20subscription%20IDs%20and%20more.%20Both%20of%20these%20can%20be%20used%20for%20specifying%20your%20subscription%3C%2FP%3E%0A%3CP%3ETo%20view%20the%20number%20of%20subscriptions%20in%20your%20login%2C%20use%20%3CEM%3EGet-AzSubscription%20%7C%20measure%3C%2FEM%3E.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58012i6F948150606F3AAC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22AzSub-01.png%22%20title%3D%22AzSub-01.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzSubscription%20%7C%20measure%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ETo%20list%20all%20of%20the%20subscriptions%20for%20your%20login%20%26amp%3B%20page%20through%20the%20list%2C%20use%20%3CEM%3EGet-AzSubscription%20%7C%20more%3C%2FEM%3E%3CSTRONG%3E.%26nbsp%3B%3C%2FSTRONG%3ENotice%20you%20get%20the%20Name%20and%20Subscription%20ID%20that%20can%20be%20used%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58013i8F2B37435F8B5B9C%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Azure-Sub-02.png%22%20title%3D%22Azure-Sub-02.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzSubscription%20%7C%20more%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20use%20copy%20and%20paste%20to%20select%20the%20Subscription%20ID%20or%20Subscription%20Name.%20Why%20do%20that%20when%20we%20can%20have%20PowerShell%20do%20the%20work%20for%20you.%20To%20views%20specific%20properties%20of%20a%20subscription%2C%20enter%20%3CEM%3Eget-AzSubscription%20-SubscriptionName%20%3CSPAN%3E%3CINSERT%20subscription%3D%22%22%20name%3D%22%22%3E%3C%2FINSERT%3E%3C%2FSPAN%3E.%26nbsp%3B%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58014i2A2267A3F83BE538%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Azure-Sub-03.png%22%20title%3D%22Azure-Sub-03.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Eget-AzSubscription%20-SubscriptionName%20%3CINSERT%20subscription%3D%22%22%20name%3D%22%22%3E%3C%2FINSERT%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EKnowing%20the%20subscription%20name%20or%20Id%20will%20allow%20you%20to%20work%20with%20resources%20by%20explicitly%20calling%20out%20the%20subscription%20information.%20But%20sometimes%2C%20you%20want%20all%20of%20your%20actions%20in%20the%20shell%20to%20be%20against%20the%20same%20subscription.%20First%2C%20you%20need%20to%20verify%20what%20subscription%20you%20are%20using%20by%20entering%20%3CEM%3Eget-AzureRMContext%26nbsp%3B%3C%2FEM%3Eto%20view%20the%20default%20subscription%20name.%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58015i09075D32A56AC082%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Azure-Sub04.png%22%20title%3D%22Azure-Sub04.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Eget-AzureRMContext%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EThis%20will%20tell%20you%20what%20Azure%20subscription%20is%20the%20default%20subscription%2C%20and%20used%20with%20all%20commands%20when%20a%20Subscription%20isn't%20specified.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20change%20the%20subscription%20context%20for%20use%20with%20all%20processes%20in%20the%20current%20user%20session%2C%20enter%20the%20following%20command%3A%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58016i07EC3C58DABFAC2E%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Azure-Sub-06.png%22%20title%3D%22Azure-Sub-06.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ESelect-AzureRmSubscription%20-SubscriptionName%20%3CINSERT%20subscription%3D%22%22%20name%3D%22%22%3E%3C%2FINSERT%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20let's%20verify%20this%20works%20as%20it%20should%20by%20creating%20a%20resource%20group%2C%20and%20then%20viewing%20all%20the%20resource%20groups%20in%20the%20default%20description.%20To%20create%20a%20resource%20group%20in%20the%20default%20subscription%2C%20enter%20%3CEM%3ENew-AzureRmResourceGroup%20-Name%20%3CRESOURCE%20group%3D%22%22%20name%3D%22%22%3E%20-Location%20%3CRESOURCE%20location%3D%22%22%3E%3C%2FRESOURCE%3E%3C%2FRESOURCE%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58017iE2CD6A031A160CBC%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Azure-Sub-07.png%22%20title%3D%22Azure-Sub-07.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3ENew-AzureRmResourceGroup%20-Name%20%3CRESOURCE%20group%3D%22%22%20name%3D%22%22%3E%20-Location%20%3CRESOURCE%20location%3D%22%22%3E%3C%2FRESOURCE%3E%3C%2FRESOURCE%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3CEM%3E%3CBR%20%2F%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3ETo%20view%20all%20the%20resource%20groups%20in%20the%20default%20subscription%2C%20enter%26nbsp%3B%3CEM%3EGet-AzureRmResourceGroup%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%3CEM%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20200px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58019i52F71FEC11065494%2Fimage-size%2Fsmall%3Fv%3D1.0%26amp%3Bpx%3D200%22%20alt%3D%22Azure-Sub-08.png%22%20title%3D%22Azure-Sub-08.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EGet-AzureRmResourceGroup%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3EAnd%20that%E2%80%99s%20it.%26nbsp%3BAll%20the%20commands%20you%20need%20to%20find%20your%20Azure%20subscriptions%20and%20start%20using%20them%20to%20build%26nbsp%3Bresources%20in%20your%20Azure%20subscription.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-276696%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F58020iBED554ED2D718281%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22AzSub-01.png%22%20title%3D%22AzSub-01.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20have%20multiple%20Microsoft%20Azure%20subscriptions%2C%20it%20can%20be%20difficult%20to%20keep%20track%20of%20them%20all.%20So%20PowerShell%20to%20the%20rescue!%20With%20the%20use%20of%20Azure%20PowerShell%20commands%20installed%20Azure%20Cloud%20Shell%2C%20I%E2%80%99ll%20show%20you%20how%20to%20view%20your%20subscriptions%2C%20and%20change%20to%20different%20subscriptions%20available%20to%20you.%20Depending%20on%20the%20type%20of%20work%20you%20are%20doing%2C%20you%20can%20either%20change%20the%20context%20of%20your%20session%20to%20use%20a%20specific%20subscription%2C%20or%20you%20can%20create%20resources%20using%20the%20Subscription%20Name%20or%20ID%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-276696%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eazure%20cloud%20shell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

If you have multiple Microsoft Azure subscriptions, it can be challenging to keep track of them all. So PowerShell to the rescue! With the use of Azure PowerShell commands installed Azure Cloud Shell, I’ll show you how to view your subscriptions, and change to different subscriptions available to you. From there, you can build resources in Azure using the default subscription.

 

Want to follow along in Azure Cloud Shell? Create a free trial account here and then browse to shell.azure.com to begin. 

 

First, let’s list out all of the Azure subscriptions you have. This will provide you the names, subscription IDs and more. Both of these can be used for specifying your subscription

To view the number of subscriptions in your login, use Get-AzSubscription | measure.

AzSub-01.pngGet-AzSubscription | measure

To list all of the subscriptions for your login & page through the list, use Get-AzSubscription | moreNotice you get the Name and Subscription ID that can be used 

Azure-Sub-02.pngGet-AzSubscription | more

You can use copy and paste to select the Subscription ID or Subscription Name. Why do that when we can have PowerShell do the work for you. To views specific properties of a subscription, enter get-AzSubscription -SubscriptionName <Insert Subscription Name>

Azure-Sub-03.pngget-AzSubscription -SubscriptionName <Insert Subscription Name>

Knowing the subscription name or Id will allow you to work with resources by explicitly calling out the subscription information. But sometimes, you want all of your actions in the shell to be against the same subscription. First, you need to verify what subscription you are using by entering get-AzureRMContext to view the default subscription name.

Azure-Sub04.pngget-AzureRMContext

This will tell you what Azure subscription is the default subscription, and used with all commands when a Subscription isn't specified.

 

To change the subscription context for use with all processes in the current user session, enter the following command:

Azure-Sub-06.pngSelect-AzureRmSubscription -SubscriptionName <Insert Subscription Name>

 

Now let's verify this works as it should by creating a resource group, and then viewing all the resource groups in the default description. To create a resource group in the default subscription, enter New-AzureRmResourceGroup -Name <Resource Group Name> -Location <Resource Location>

Azure-Sub-07.pngNew-AzureRmResourceGroup -Name <Resource Group Name> -Location <Resource Location>

To view all the resource groups in the default subscription, enter Get-AzureRmResourceGroup

Azure-Sub-08.pngGet-AzureRmResourceGroup

And that’s it. All the commands you need to find your Azure subscriptions and start using them to build resources in your Azure subscription.