Getting started with Windows Azure PowerShell

Windows Azure PowerShell is a module that includes PowerShell cmdlets that can be used to manage windows_azure1Windows Azure objects.  Why would you need this?   PowerShell allows us to manage and create or remove objects programmatically using scripts or interactively through the PowerShell command line.  I have found using PowerShell to manage Windows Azure extremely useful in many areas and especially when creating new objects.  For example you can use a PowerShell script to create a virtual machine, install Active Directory AND promote it to a domain controller without even logging onto the VM itself !   A more common scenario is to create a virtual machine, add a disk, a load balancer, set the RDP port and join the domain.  This can be done very easily with the use of a PowerShell script rather than manually creating it in the Azure portal which takes longer and as with all manual methods, increases scope for misconfiguration and inconsistency in your environments.

This article and related video shows the steps required to get up and running with Azure PowerShell.  Further articles will detail specific use cases.

What do you need to get started ?

You will need:-

  • A machine that can install the Azure PowerShell Azure module (Windows RT will not work here)
  • An internet connection
  • An active Azure subscription.
    Microsoft offer a free trial which is available from here :-

image

I have created a video to accompany this article for those that want to see it in action.

I am using Windows 8.1 Enterprise which comes pre-installed with PowerShell and so we just need to add the Azure cmdlets which can be done by going to the Windows Azure site, Downloads, Command-Line Tools.  Download the latest Windows Azure PowerShell module for your OS, Windows, Mac or Linux.

Direct link is here :-

http://www.windowsazure.com/en-us/downloads/#cmd-line-tools

image

Once this is complete, add it to your task bar, right click and open ISE as administrator.  To find the Azure console go to your start screen and type Azure, then right click on the correct Azure PowerShell icon to add it to your task bar.

image

Then right click the icon and open as Administrator.

image

 

Import your Azure Subscription Publish Settings File

This file contains xml data about your main subscription and any other subscriptions you have been granted co-administrator access to and a certificate which this process generates.   When this file is imported the required certificate is installed on your local computer certificate store and is then used for authentication.  If you have multiple Azure accounts log out of them to ensure you get the option to sign into the one you want the xml file for.

First you must get the file and then import it before you can manage your desired Azure subscription.  You will then need to tell PowerShell the name of the subscription you with to use.  See screen shot here taken from the video for an example :-

image

Key cmdlets are Get-AzurePublishSettingsFile and Import-AzurePublishSettingsFile

Then Set-AzureSubscription and Select-AzureSubscription

Set-AzureSubscription will configure the subscription common information to store in the users profile and the Select-AzureSubscription will make the selection current.

The above example shows the use of a variable to set the name of the subscription which you have access to.

Create Affinity Group

An affinity group is a name you provide that ties objects together in a particular Azure region (not data centre) to minimize latency between objects such as network, storage and servers,  We will look at affinity groups more in another article and we will use “North Europe” here in our examples.

You can see here in my demo account that there are several test affinity groups created from Settings, Affinity Groups.

image

If you select Add you will see the available regions and can specify a name and description.

image

To specify the region and create the affinity group in Azure using PowerShell use the following script :-

$myAffinityGroupName  = ‘NorthEuropeAffinityGroup’

$WindowsAzureRegion   = ‘North Europe’
New-AzureAffinityGroup -Name $myAffinityGroupNameLocation $WindowsAzureRegion

I have used two variables to specify the information required which are name and region as shown in the GUI above.

Running the above three lines creates the affinity group.

Create Storage Account

In order to create virtual machines you will need to create a storage account and location in which to store the VM VHD files.

The screenshot below shows the portal storage creation screen which prompts for name, location and geo-replication option.  If you have more than one subscription selected in your subscriptions tab at the top of the screen you will see the option to select which subscription you want to create the storage in.

image

The following will create the storage container.  The affinity group variable is above.

$myStorageAccountName = ‘mystorageblob’

New-AzureStorageAccount AffinityGroup $myAffinityGroupName -StorageAccountName $myStorageAccountName

Once this is complete you should be able to start building Azure objects.

A video showing how to get up and running with PowerShell is here below.

 

Thanks for reading !

Currently a further tutorial and scripts are available here http://bit.ly/1dtpzx8

I hope you found this article useful and if you would like me to add or clarify anything let me know and I will try and update it.   If you would like to put a comment below if you found this helpful that would be great too.

Advertisements

About Mitesh Chauhan
Mitesh Chauhan, Azure Cloud Solutions Architect. This is my blog where I share articles and thoughts on IT Infrastructure and architecture. The topics I am most passionate about are Implementation and architecture of rock solid Cloud Infrastructure based around SQL Server and Windows Server mainly using Microsoft Azure. MCTS - Azure Architecture MCTS - Azure Implementation MCSE Server Infrastructure (Windows Server 2012) , MCITP SQL Server 2008, Togaf Certified, Prince 2 Practitioner.

One Response to Getting started with Windows Azure PowerShell

  1. Pingback: Creating an Azure Files | IT Infrastructure and Architecture Methods and Recipes

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

%d bloggers like this: