Connecting to Azure

After the installation of the Azure module shown in the last section, a few simple scripts that use some Azure cmdlets are going to be demonstrated. Of course, you must have at least a "Free Trial" account in Microsoft Azure to reproduce the following scripts. A Free Trial account can be quite easy created at -> Try for free.
In order to get access to a free trial, you need a Microsoft account (,,, etc.) and you must also provide your credit card information. Microsoft promises to use your credit card information only to check your identity and not to bill you unrequested purchases. I assume and sincerly hope that they will maintain their promise!
After registration you will own a 29-Day Trial Subscription and have a €150 credit that can be used during the trial period. After 29 days or the €150 credit has been spent, whichever occurs first, the trial period ends. I assume that a credit of €150 is more than sufficient for extensive testing, but unfortunately after only 29 days a new registration for a new trial subscription is required.

All useful information about your subscription can be found on the left menu bar (i.e. side bar) in the "SETTINGS" menu point. The Subscription Name ("Free Trial") and the SubscriptionID can be found on the main panel. Of course, this information can also be read out with Powershell. See chapter 1.1. 

1. Connecting to the Azure Cloud

There are two ways to enable a local Powershell instance (with Azure module) to the Microsoft Azure Cloud. Both ways, as well their differences, are going to be shown in the chapters here below.  


1.1 Add-AzureAccount

One easy way to connect your local computer with your Azure Subscription is by using the cmdlet "Add-AzureAccount". After executing this cmdlet you will get a prompt to enter your credentials:


If everything goes well you can get information about your subscription by using the cmdlet "Get-AzureSubscription"


#possible result

SubscriptionId            : 6f8d8519-20ef-453e-9fd9-1ccde21717a7
SubscriptionName          : Free Trial
Environment               : AzureCloud
SupportedModes            : AzureServiceManagement,AzureResourceManager
DefaultAccount            :
Accounts                  : {}
IsDefault                 : True
IsCurrent                 : True
CurrentStorageAccountName :
TenantId                  : b8aaf5a3-202a-491a-9edc-2fae0bb63a5f


To remove the connection between your local Powershellsession and the AzureSubscription, please use the cmdlet "Remove-AzureSubscription"

$Subscription = "Free Trial"
Remove-AzureSubscription $Subscription

Do not worry, you can re-Add and Remove your subscription as often as you want. The subscription itself is not permanently removed by using the cmdlet "Remove-AzureSubscription" 

In all cases, it is a good idea to always check and make certain that the successful logoff has been successful by using the cmdlet "Get-AzureSubscription", where you should get an empty result. 



1.2 Get-AzurePublishSettingsFile

The second way to establish a connection between a local Powershell instance and Windows Azure is to use a "Management Certificate File" by using the cmdlet Get-AzurePublishSettingsFile.


When you are logged on to your subscription in your browser, you will see this screen shot, which prompts you to download the Certificate file.

Subsequently, the just downloaded certificate file still has to be imported by using the cmdlet "Import-AzurePublishSettingsFile"

$DownloadPath = "C:\Users\powershellpraxis\Downloads"
Import-AzurePublishSettingsFile $DownloadPath
#possible result
Id          : 6f8d8519-20ef-453e-9fd9-1ccde21717a7
Name        : Free Trial
Environment : AzureCloud
Account     : B63903B703491452FE8E427E56C13523F1938394
Properties  : {[SupportedModes, AzureServiceManagement]}

A subsequent check should show the successfully built connection.

#possible result
SubscriptionId            : 6f8d8519-20ef-453e-9fd9-1ccde21717a7
SubscriptionName          : Free Trial
Environment               : AzureCloud
SupportedModes            : AzureServiceManagement
DefaultAccount            : A0F91CD4C9FB1B525F2306B8441EB09DDF9B2D83
Accounts                  : {A0F91CD4C9FB1B525F2306B8441EB09DDF9B2D83, B63903..}
IsDefault                 : True
IsCurrent                 : True
CurrentStorageAccountName : 
TenantId                  : 

As shown in the foregoing chapter the connection can be deleted by using the cmdlet "Remove-AzureSubscription".

$Subscription = "Free Trial"
Remove-AzureSubscription $Subscription

1.3 the Difference between Add-AzureAccount and Get-AzurePublishSettingsFile

Both the "Add-AzureAccount" and the "Get-AzurePublishSettingsFile" can be used to set up a connection. But be aware that the available SupportedModes are different.

method to set up the connection SupportedModes
Add-AzureAccount 1) AzureServiceManagement
2) AzureResourceManager


1) AzureServiceManagement

Both the SupportedModes offer different cmdlets to be executed. In order to avail of the cmdlets from the AzureResourceManager the connection between local computer and the AzureSubscription must be established by using the cmdlet "Add-AzureAccount" and consequently, the mode must be switched by using the cmdlet "AzureResourceManager"

Switch-AzureMode -name AzureResourceManager