Azure Virtual Machine quick provisioning using Azure Powershell

Dear PUG community members,
I am excited about new launch of PUG blog. I have been associated to PUG since March 2014 and it has been excellent journey till now. Starting a blog is really a great initiative and it will help all of us to reach to new set of audience, expand the horizons of PUG community to new heights.
Alright so let’s get started. In this blog post I am going demonstrate how you can provision plain Windows Server 2012 OS based VM on Azure IaaS platform using Azure Powershell commands.

Prerequisites –

1. Azure subscription. You can have free trial of 1 month from this link.
2. Azure powershell. You can have Azure powershell installed from this link.
3. I assume that you are aware of VM provisioning from Azure Management Portal.
4. I am using Azure powershell 0.8.7 version which is part of Azure SDK 2.3 to demonstrate all below mentioned operations.

Setting up connection and subscription

Authentication is the basis for any Azure operation using powershell. To make yourself authenticated user to your subscription there are 2 ways. Either you can use publish settings file or use command Add-AzureAccount.
Go to powershell ISE from start menu [I am using Windows 7…yes I am still on Windows 7 because I just love it…] as an administrator and add following tow commands –


1 2

If you use command Add-AzureAccount then powershell ISE throws a pop up where you need to put your live id credentials which have co-admin or admin access on Azure subscription.
3
Ok now we have setup the connection to our Azure subscription but we have not selected subscription to work upon. So we need to setup subscription to be used for commands that will provision new VM. To know your subscription name, go to Azure Management Portal. Select Settings tab and record the name of your subscription.
4
The option is to use power shell command to list down all the subscriptions associated to your live id. To get list of subscriptions use following commands –


Fire the following command and provide the name of subscription you recorded in above step when prompted –

This completes the setup of Azure connection and subscription.

Setting up Storage Account

Azure Storage is mandatory for creating a VM on Azure. When you provision a VM, by default the underlying media means .vhd file of your VM is stored in Azure Storage Blob offering. Explanation of Azure Blob Storage is out of scope of this article.
The .vhd files are stored in Azure storage as page blobs. Therefore if you don’t provision storage account name then automatically a guid based storage account will be provisioned. But that storage account name will not be user friendly. Therefore it is best practice always to create a storage account at first before provisioning Azure VM. Following commands can be used to create a new storage account name –

Now newly created storage account must be set as default storage account for the current subscription. Therefore execute below command to set Azure storage account for current subscription –

Setting up Cloud Service

Cloud service acts as a container for your Azure VM, web and worker roles. Therefore to provision VM, cloud service is mandatory. To create cloud service using powershell execute following command –

Retrieving name of Image

Azure VM’s are provisioned based on template image that you select from gallery option. As in this post I am going to create Windows Azure 2012 DataCenter OS based VM. Therefore we should retrieve the latest version available for the same family. Use below command to get latest image version available in the region SouthEast Asia –

Provisioning VM

Now we are all set to provision new VM for our subscription. Let me summarize the list of operation one need to perform to quickly create VM is as follows –
– Add azure account information in powershell window
– Select subscription to work
– create required storage account and set it as default for the current subscription
– create cloud service
– retrieve the required image family latest version
– Use New-AzureQuickVM command to create desired Azure virtual machine
The command to provision new VM is as follows –

The above command provisions VM in your subscription and can be viewed in the management portal as shown below –
5
This completes the Azure Virtual Machine provisioning using powershell with basic configuration.

If you are interested in understanding the common operations to be performed on Azure virtual machine using powershell then refer to the link – http://sanganakauthority.blogspot.com/2014/07/azure-virtual-machine-using-powershell.html
The source code powershell commands for common operations is present at the bottom of post.
Please provide your comments/ suggestions/ feedback to improve this article.

Happy Cloud Computing!!
Cheers…

Kunal is Microsoft Azure MVP and Azure Trainer. He works with organizations to help them migrate applications to Azure, provides consultancy, architectural decisions on Azure projects. He is a very active member in various Microsoft Communities and passionate ‘Speaker’ in many events.

Leave a Reply