
close
close
Microsoft provides us with several different virtual machine templates that lets us quickly deploy virtual machines in Azure. However, it’s rare that you need a standard virtual machine; maybe you need some roles or features added, install some software, or force some other kind of change. If you can script what you need, then the good news is that you can make it happen thanks to the Custom Script extension.
One of the options when you deploy a new Azure virtual machine is to install extensions. One of these extensions is called the Custom Script extension. As Microsoft explains, this extension can load a script into a virtual machine and execute it for you using system privileges after the virtual machine has been deployed.
This means that if you can script a change by using PowerShell, then you can automate that change automatically after the virtual machine has been deployed by using the Custom Script extension.
advertisment
The first step is to write a script that will make the required change. Author your script and save it somewhere safe. If this is a one-off script, then you can keep it on your PC. If you are going to reuse the script, then upload it to a storage account in Azure. In my example, I have uploaded a script to a container called scripts in a storage account named petridemo.
Verifying that the file was uploaded to the Azure Storage Account (Image credit: Aidan Finn)
If you are using the management portal, then go through the normal wizard to create a virtual machine.
Creating a new Azure virtual machine (Image credit: Aidan Finn)
Enabling the Custom Script extension in the virtual machine configuration wizard. (Image Credit: Aidan Finn)
advertisment
I have already uploaded a script to Azure, so I clicked From Storage. A new dialog appears; expand the required storage account, browse into the necessary container, select the script that you want to use, and click Open.
Select a script from an Azure Storage Account (Image Credit: Aidan Finn)
A configured Custom Script extension (Image Credit: Aidan Finn)
advertisment
If PowerShell and automation are things that appeal to you, then the Custom Script extension offers a lot of promise, as you might realize if you read the excellent article, Understanding Azure Custom Script Extension, by Ravikanth Chaganti (MVP) on PowerShell Magazine. Some interesting options include:
Give it a spin, and let me know your thoughts in the article comments below.
More in Microsoft Azure
Build 2022: Microsoft's Intelligent Data Platform Combines Data and Analytics
May 25, 2022 | Rabia Noureen
Microsoft Revises Restrictive Cloud Licensing Policies to Avoid EU Antitrust Probe
May 19, 2022 | Rabia Noureen
Microsoft's Azure AD Conditional Access Service Can Now Require Reauthentication
May 13, 2022 | Rabia Noureen
Microsoft Addresses Cross-Tenant Database Vulnerability in Azure PostgreSQL
Apr 29, 2022 | Rabia Noureen
Microsoft Simplifies IT Monitoring with New Azure Managed Grafana Service
Apr 19, 2022 | Rabia Noureen
Most popular on petri