Buy Me a Coffee

Buy Me a Coffee!

Saturday, May 3, 2014

Stop clicking webpages to control Azure!

I spent all day yesterday setting up a new set of lab machines for work on Windows Azure, and boy, did my mouse hand ache afterwards!  Well, not really, but I did have several false starts at building the first VM as I had to go back and add in my Network and Storage so that I could keep things tidy.  I know what I need to do, I just don't (and don't want to) do it often enough to keep the different tasks ordered in my head.

The first thing to needed to begin working Azure account from PowerShell is to install PowerShell (if requried) and connect your Azure subscription to your machine.  The process is pretty straight forward and is fully described in the Microsoft article How to install and configure Azure PowerShell.  I just downloaded the Microsoft Web Platform Installer as instructed and added the Azure tools.  I then opened up the Azure PowerShell console and typed in

        PS C:\> Add-AzureAccount

Which prompted me to log in:

Sign in to Windows Azure window showing different Microsoft accounts to choose from.
Sign in to Windows Azure prompt window
Once I had logged in, I was able to run all sorts of cool commands.  One big question I had was because I have several different live accounts that have Azure accounts associated with them.  Was I going to have to choose one and forget about using the rest?  Of course not.  All you have to do is type in:

        PS C:\> Select-AzureSubscription <subscription name>

which is really cool if all of your subscriptions have different names!  I had a couple that were the same, both MSDN account related: one for work and one for my side business. Luckily, someone had already asked the question on StackOverflow and the answer was simply to rename the accounts (link).

Edit:  Interesting!  The issue that I was complaining about above was based on the assumption that once the account was connected to a machine, it would stay.  That isn't the case!  Using the method above to associate an Azure account with a session will expire:
A snip from a PowerShell window showing "Your Windows Azure credential in the Windows PowerShell session has expired."
Your Windows Azure credential in the Windows PowerShell session has expired.