In our industry, we have gotten used to an exponential rate of development and progress. The Azure family is no different, and it’s easy to get lost. In this article, we’re going to go through the basics of managing Azure via PowerShell.
Azure PowerShell vs. AzureRM PowerShell
Microsoft Azure PowerShell Module is the first version Microsoft released. It’s based on the old management portal and uses their terminology. Azure PowerShell before 1.0 used these modules. Going forward, Azure Resource Manager (ARM) technology is the common basis. Both the new portal and Azure PowerShell v1.0+ use ARM. I recommend focusing on AzureRM modules wherever possible.
Connection to AzureRM PowerShell
Install AzureRM PowerShell from the Gallery if you haven’t done so yet.
Install-Module AzureRM
Next, you log in to your account.
Login-AzureRmAccount
Take a look at which subscriptions you have access to.
Get-AzureRmSubscription
If you have more than one subscription, select the subscription you want to manage.
Select-AzureRmSubscription -subscriptionId xxx
Now you’re ready to execute any command you like. Any commands apply to the subscription you selected.
Common Parameters
There are a couple of parameters that can be appended to any cmdlet in PowerShell.
The most common ones I use are:
-Verbose (short: -vb)
This can be used to increase the output a command creates. Not all commands support it, though.
-Debug (short: -db)
For many commands, this will output step-by-step programmer comments. It’s useful when the error output does not indicate where a problem occurred. But be warned: You will often have to confirm every step before it occurs.
-ErrorAction (short: -ea)
Some cmdlets may show errors during execution but continue nevertheless. You can override this behavior and, for example, stop on any error (-ea:Stop
). Or ask the user to decide (-ErrorAction:Inquire
).
-OutVariable
Stores the output of the cmdlet into a variable (-ov:variablename
) or appends it to one (-OutVariable variablename
).
Note the long and short versions are interchangeable. Also, you can specify a parameter with or without a semicolon. For strings with spaces, use quotation marks.