Azure Virtual Machines Agent and Extensions

Santosh Gaikwad

Connect on LinkedIn      Follow SCI Page

Write to
Santosh Gaikwad

Latest posts by Santosh Gaikwad (see all)

<< Azure VM      >> Azure

The Azure Virtual Machines Agent (VM Agent) is a secured, light-weight process that installs, configures, and removes VM extensions on instances of Azure Virtual Machines. The VM Agent acts as the secure local control service for your Azure VM. There are two Azure VM Agents, one for Windows VMs and one for Linux VMs. By default, the VM Agent is automatically installed when you create a VM from the Image Gallery.

Azure virtual machine extensions

VM Extensions are small applications that provide post-deployment configuration and automation tasks on Azure virtual machines. For example, if a virtual machine requires software installation, anti-virus protection, or Docker configuration, a VM extension can be used to complete these tasks. Azure VM extensions can be run by using the Azure CLI, PowerShell, Azure Resource Manager templates, and the Azure portal.

Extensions can be bundled with a new virtual machine deployment or run against any existing system.

Different Azure VM extensions

There are many different Azure VM extensions available, each with a specific use case.

Some example use cases are:
Configure virtual machine monitoring using custom script or PowerShell DSC.
Configure an Azure virtual machine by using Chef.

How to check if VM agent is installed

When logged in to a Windows Azure VM, task manager can be used to examine running processes. To check for the Azure VM Agent, open Task Manager > click the details tab, and look for a process name WindowsAzureGuestAgent.exe.

The presence of this process indicates that the VM agent is installed.

Custom Script Extension for Windows VM

The Custom Script Extension downloads and executes scripts on Azure virtual machines. This extension is useful for post deployment configuration, software installation, or any other configuration / management task.

Scripts can be downloaded from Azure storage or GitHub, or provided to the Azure portal at extension run time. The Custom Script extension integrates with Azure Resource Manager templates, and can also be run using the Azure CLI, PowerShell, Azure portal, or the Azure Virtual Machine REST API.

The Azure custom script extensions allow the owner of the Azure VM to run script stored in Azure storage during or after VM provisioning.

The script extension only executes once per VM, not every time the machine boots up – but if you stop the VM via Azure portal, and start the VM again, the VM will be re-provisioned, so the script will run again.

If you need to run scripts repeatedly, you can add a timestamp parameter to your custom script extension.

Deploy Extension using PowerShell

The Set-AzureRmVMCustomScriptExtension command can be used to add the Custom Script extension to an existing virtual machine.

Following is a example of Powershell script to create new website in IIS (MyScript.ps1), upload this file in Azure blob storage and refer same in PowerShell script.

Import-Module WebAdministration
 $iisAppPoolName = "my-test-app"
 $iisAppPoolDotNetVersion = "v4.0"
 $iisAppName = "my-test-app.test"
 $directoryPath = "D:\SomeFolder"
 #navigate to the app pools root
 cd IIS:\AppPools\
 #check if the app pool exists
 if (!(Test-Path $iisAppPoolName -pathType container))
     #create the app pool
     $appPool = New-Item $iisAppPoolName
     $appPool | Set-ItemProperty -Name "managedRuntimeVersion" -Value $iisAppPoolDotNetVersion
 #navigate to the sites root
 cd IIS:\Sites\
 #check if the site exists
 if (Test-Path $iisAppName -pathType container)
 #create the site
 $iisApp = New-Item $iisAppName -bindings @{protocol="http";bindingInformation=":80:" + $iisAppName} -physicalPath $directoryPath
 $iisApp | Set-ItemProperty -Name "applicationPool" -Value $iisAppPoolName

Set-AzureRmVMCustomScriptExtension -ResourceGroupName myResourceGroup `
    -VMName myVM `
    -Location myLocation `
    -FileUri myURL `
    -Run 'myScript.ps1' `
    -Name DemoScriptExtension

VM Extension PowerShell Script
PowerShell Script to install VM Extensions

Execute PowerShell script to update VM after setting up extension.


<< Azure VM      >> Azure

Check Articles From Categories      Health and Parenting      Inspiring Stories      Technology      Microsoft Azure      SharePoint O365

Leave a Reply

Your email address will not be published. Required fields are marked *