Introduction

Deploying a Virtual Machine in Azure can be done using the Azure Portal or using the command-line such as Azure PowerShell and Azure CLI. After deploying a Virtual Machine, you will need to configure the VM to suit your needs. In a perfect world, we need to automate our most important tasks in order to save time.

With Azure VM Extensions, you can configure for example:

Monitoring

Security

Configuration management

Backup

And more…

Azure Virtual Machine Extensions are small applications that provide post-deployment configuration and will simplify the configuration management of Virtual Machines. This feature uses Windows and Linux Azure agents that are automatically installed during the provisioning process. This agent is named ‘Microsoft Azure Virtual Machine Agent’ and it is the only prerequisite in order to use the Azure VM Extensions.

Listing Azure VM Extensions

As shown below, you can see the list from the Azure Portal by navigating to the Virtual Machine blade:

Go to the Azure portal .

. Locate the Virtual Machine that you want to add Extension.

Click Extensions in the Settings area

You can also use Windows PowerShell to list the Azure VM Extensions using the following command. The Get-AzureRmVMExtensionImage cmdlet will list the VM Extensions available in the West Europe region:

PS > Get-AzureRmVmImagePublisher -Location <Azure_Region> | ` >> Get-AzureRmVMExtensionImageType | ` >> Get-AzureRmVMExtensionImage | Select Type, Version 1 2 3 4 5 PS > Get - AzureRmVmImagePublisher - Location < Azure_Region > | ` >> Get - AzureRmVMExtensionImageType | ` >> Get - AzureRmVMExtensionImage | Select Type , Version

At the time of writing this article, in the West Europe region, there are 879 VM extensions at your disposal.

Using Azure VM Extensions

First, you need to check the VM Agent status using the following command:

PS > Get-AzureRmVM -Name <VM_Name> -ResourceGroupName <RG_Name> | Select -ExpandProperty OSProfile | Select -ExpandProperty Windowsconfiguration | Select ProvisionVMAgent 1 PS > Get - AzureRmVM - Name < VM_Name > - ResourceGroupName < RG_Name > | Select - ExpandProperty OSProfile | Select - ExpandProperty Windowsconfiguration | Select ProvisionVMAgent

The command returns True, which indicates that the VM Agent is installed, and running.

Log in to the VM and open the Task Manager to check the WindowsAzureGuestAgent.exe process. It means that the VM Agent is installed:

To finish with the Azure Agent, it is located in the following directory: C:\WindowsAzure

Installing Azure VM Extensions

Using the Azure Portal, you can easily add an extension to an existing Virtual Machine. Navigate to an existing Virtual Machine, then select Extensions and click Add.

Select the Extension you want to install from the list of extensions. In my case, I selected the Custom Script Extension, which is a tool that can be used to launch and execute customization tasks. With this extension, you can run PowerShell scripts to configure the Virtual Machine.

Provide the configuration parameters as required. Here, you must provide the script file and arguments.

Click OK to start the installation process.

Custom scripts are great to perform specific tasks. There are just few things to take into consideration, such as:

The script can be stored on GitHub, Azure Blob Storage, or anywhere the VM can access the repository.

If your script is located on the Internet, then the firewall rules must be opened.

If you run a bash script, for example, you must run the script on supported OS’s (e.g. Linux OS)

Now, if you deploy a new Virtual Machine, you will notice the following tab called “Guest config“. The VM Extension can be configured within the deployment wizard.

Once the VM Extension is installed, you can check the status in the Extensions blade:

In my case, I can see two VM Extensions:

A Custom PowerShell Script

The Site24x7 agent

It is possible to check if there are VM Extensions already installed on a Virtual Machine using the Get-AzureRmVM cmdlet:

PS > Get-AzureRmVM -Name <VM_Name> -ResourceGroupName <RG_Name> | Format-List * 1 PS > Get - AzureRmVM - Name < VM_Name > - ResourceGroupName < RG_Name > | Format - List *

To install a new VM Extension, there are several PowerShell cmdlets at your disposal that you can list using the following command:

PS > Get-Command Set-AzureRM*Extension* 1 PS > Get - Command Set - AzureRM* Extension*

Here is an example of custom script implementation with PowerShell:

PS > Set-AzureRmVMCustomScriptExtension -ResourceGroupName <RG_Name> ` -VMName <VM_Name> ` -Location <Location> ` -FileUri <Script_URL> ` -Run <Command_to_execute> ` -Name <Extension_Name> 1 2 3 4 5 6 7 8 9 10 11 PS > Set - AzureRmVMCustomScriptExtension - ResourceGroupName < RG_Name > ` - VMName < VM_Name > ` - Location < Location > ` - FileUri < Script_URL > ` - Run < Command_to_execute > ` - Name < Extension_Name >

You can store a custom script in your Azure Blob storage.

VSAN from StarWind eliminates any need for physical shared storage just by mirroring internal flash and storage resources between hypervisor servers. Furthermore, the solution can be run on the off-the-shelf hardware. Such design allows VSAN from StarWind to not only achieve high performance and efficient hardware utilization but also reduce operational and capital expenses. Learn more about ➡ VSAN from StarWind

Conclusion

Thanks to Azure Virtual Machine Extensions, you can very easily and quickly configure your machines. You can also automate tasks that you performed manually.

If the agent is not installed in the Virtual Machine, you can install it very easily. In this case, you can download the agent and double-click the Windows installer file.

Thanks for reading!

Related materials:

Views All Time Views All Time 20 Views Today Views Today 40

Appreciate how useful this article was to you?

5 out of 5, based on 1 review 5 out of 5, based on 1 review

Loading... Loading...