When you start working with Azure, you start with one subscription. It tends to be private for your own use. All is good.

Over time you gain experience working with Azure and perhaps you start working with a client. They give you access to their corporate subscription. Now you have to remember to switch between subscriptions and this can become a burden.

In time not only have you amassed more clients but they’ll also be putting their Azure projects into production. You might have access to these production subscriptions. Now the impact of deploying a change to the wrong place becomes larger and mistakes become inevitable.

All that power sits behind a single Windows Live account. Single Sign On is useful in many situations but maybe not in this case!

In Azure your Live account is added to a directory. Directories can relate to zero, one or more subscriptions. In both the old and new Azure portals when you select either the subscriptions option or switch between accounts what you are actually doing is switching directories. You are not switching subscriptions directly. As far as I know a subscription cannot be related to multiple directories.

azure1
Selecting a directory – Old Portal
azure2
Selecting a directory – Old Portal

When you switch directories and therefore subscriptions you want to know at a glance which one you are in. The old portal doesn’t give many options here, so as most of us have switched to the new portal the rest of this post will focus there.

The first option is to change the theme for each directory. You can do this by using the Settings option on the top right of the screen. However, you are limited to four options and they are quite similar. Changing the theme is the first step of customising the portal experience. I recommend that you configure the portal dashboard for each directory to reflect its purpose. That should give you a visual clue as to whether you have the correct directory selected.

It seems as those the Azure portal remembers the directory and subscription you were last using and that is the one it starts with when opening up the portal next time. That may or may not be useful. I have noticed though that you can pass the name of a directory as part of the query string to force the portal to start in a given directory.

For example

https://portal.azure.com/signin/index/{directoryName}

With this knowledge you can create a group of shortcuts with descriptive names to ensure you are always in the correct place.

But perhaps the simplest thing to do is add a markdown widget to the dashboard. This can contain anything but it can be used to clearly identify where you are working.

That is all well and good if you are using the portal. But what happens if you are staring into the blue abyss that is the PowerShell command prompt. How do you ensure that you are working in the right place then?

ps
The dark blue abyss…

This requires a bit more discipline and care. It is quite easy to made mistakes. The classic Azure model had the concept of a default subscription. This article explains how that works in PowerShell. However, this is not so straight forwards with the newer Resource Manager model. You’d like to think it was just a case of adding RM to the appropriate parts of the command so

 Get-AzureSubscription

Becomes

Get-AzureRmSubscription

Whilst this works for some command the results are not exactly the same.

If you are using the RM model you use the following command to login

Login-AzureRmAccount

This gives you access to all your subscriptions. You can see them all with

Get-AzureRmSubscription

This gives you the name, subscriptionId and tenant Id. Many subscriptions can exist in a single tenant. You then select a subscription with

Select-AzureRmSubscription -SubscriptionID $subscriptionId

So you can select the subscription but how do you find out what is currently selected. The following command comes to your assistance

(Get-AzureRmContext).Subscription

For a belt and braces approach you can combine these commands at the top of your scripts to ensure that you only ever work on the intended subscription.  A small price to paid for stress free Azure scripting.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s