Written by: Daniel Haurey on 01/03/17

This article describes automating the process of provisioning an Azure VM (Virtual Machine) and tearing it down. Before we start, let’s clarify few terms:

Azure

When we talk about Azure it is understood that we’re talking about Microsoft’s public cloud offering. This is sometimes referred to as Azure commercial. In Powershell, this is referred to AzureCloud. Microsoft has separate clouds from Azure such Azure US GOV cloud for US Government organizations (not available to the public).

ARM vs ASM

Azure has two APIs/modes;

  • ASM (Azure Service Management) also referred to as ‘classic’. ASM mode will evantually be phased out.
  • ARM (Azure Resource Manager) which is the current (new) one. This can be accessed from https://portal.azure.com

There are different capabilities between resources provisioned in each mode. This article will use Azure ARM (new) portal, API, Powershell cmdlets and capabilities.

Azure Powershell

To get started with Azure Powershell, you need to download and install the Microsoft Web Platform installer.

Microsoft Web Platform installer Microsoft Web Platform installer

Powershell version 5 which comes with Windows 10 and Server 2016 is required. Windows 8, 8.1, Server 2012 and Server 2012 R2 can have their Powershell 4 upgraded to 5. To see your Powershell version, in Powershell ISE type in $PSVersionTable

PSVersionTable PSVersionTable

Obtaining the script

The script can be downloaded from the Microsoft Technet Gallery under Windows Azure.

Script Input

The script takes the following parameters:

  • SubscriptionName: This is the name of existing Azure subscription
  • Location: name of Azure location (data center). To see a list of Azure locations use these cmdlets:

Get-AzureRmLocation | sort Location | Select Location

Azure Locations Azure Locations

  • ResourceGroup: Select a name for your Resource Group. A Resource Group in the ARM mode provides a logical grouping of resources and simplifies resource management.
  • StorageAccountName: This is the name of the storage account where the VM VHD disk files will be stored. The script will create it if it does not exist.  Only lower case letters and numbers are allowed.
  • AdminName: This will be the new VM local administrator
  • VMName: Name(s) of VM(s) to be created. Each has 15 characters maximum
  • VMSize: Size of Azure VM which determines its resources. To see the available VM sizes use this cmdlet:

(Get-AzureRoleSize).RoleSizeLabel

Azure VM Sizes Azure VM Sizes

  • vNetName: This will be the name of the virtual network to be created/updated if it exists
  • vNetPrefix: To be created/updated
  • SubnetName: This will be the name of the subnet to be created/updated
  • SubnetPrefix: Must be subset of vNetPrefix above

Here’s a sample script output:

Deploy Azure ARM VM Script Output Sample Deploy Azure ARM VM Script Output Sample

You can also view all the objects created by the script in the Azure portal:

Azure VMs created by Deploy Azure ARM VM Powershell script Azure VMs created by Deploy Azure ARM VM Powershell script

Click on the Resource Groups icon towards the top left to open the Resource Groups blade. Click on the ‘VMGroup2’ resource group that was created by the script to open the ‘VMGroups2’ blade. Review all the objects created by the script and their properties.

Tearing down is fairly simple, and it demonstrates the power of resource groups. Simply delete the VMGroup2 resource groups, and all the objects under it are deleted automatically.

For large scale deployments, complex deployments, and advanced features and capabilities, contact Exigent Azure Consulting team.