Azure Automation using Custom Script Extension – Part 2

Azure Automation using Custom Script Extension – Part 2

In the first part of the series – article Create Custom Image in Microsoft Azure, we saw how to create Custom Image in Microsoft Azure. In this article, I will walk you through using Custom Script Extension feature of Microsoft Azure, that lets you execute PowerShell scripts once the Operating System is deployed.

In this example, you will deployment of Operating System on Azure, install Windows Role/Feature and silently deploy an application Firefox.

Preparing Azure Blob Storage & Container

Create Azure Blob Storage. Login to Azure Account & give a unique name. In the example below you see little “red” color escalation mark. This was because I didn’t take screen shot earlier. There needs to be “green” color tick mark before you continue with successfully creating Storage account

Now create Container named “scripts” and with access type as “Public Container” . This will be used to store the PowerShell script used by Custom Script Extension.

Preparing Azure File Services for storing Software Installers

Login to New Azure Portal – portal.azure.com, go to Storage Account that was created above, click on Files and create a File Share named installers. This will be used to store the installers like Firefox in this example.

Quick recap, we have now created a Azure Storage Account named goel, created a page blob named scripts and have a File Share named installers, in North Europe region.

Page Blob – Scripts – https://goel.blob.core.windows.net/scripts

File Share – Installers – \\goel.file.core.windows.net\installers

Connect to File Share and upload Installers

In order to connect to Azure File Share, you need a Virtual Machine on Azure to access via SMB method (I guess this is because Azure might have locked the source IPs to Azure regions, I have not explored why I can’t to connect to Azure File Share from my home computer. Leaving this for investigation for later). We need a Azure Storage Primary Key to connect to Azure share.

Connect to Azure Subscription by executing

Add-AzureAccount

Once you add your Azure Account to PowerShell, execute the command shown below to get your Primary and Secondary Keys. Copy the Primary key.

Get-AzureStorageKey -StorageAccountName <your-account-name>

Now login to one of the Azure VM, connect to Azure File share and copy the Firefox installer

Next, we create a new VM and deploy it in new or existing Cloud Service Customtest1.

Please note that Location of the Virtual Machine should be same of your Custom Image that we created in Part-1. If you use default Microsoft VM Image then could use any supported Azure region for the OS Image.