Azure extensions are small applications that you can add to VMs after deployment that provide VM configuration, monitoring, security, and utility features. For example, the Custom Script Extension allows execution of a script on VMs, and the Azure Monitor Agent allows collection of information such as CPU, memory, disk, or network usage of the VM.

Beginning with Citrix Virtual Apps and Desktops version 2209, Machine Creation Services (MCS) supports provisioning catalogs with Azure VM extensions. By default, Citrix has enabled a short allowlist of extensions that can be displayed with Get-ProvMetadataConfiguration. You can add to or remove from the list other extensions using the PowerShell commands Add-ProvMetadataConfiguration and Remove-ProvMetadataConfiguration.

Due to Microsoft limitations, some extensions might not be exported when using a VM as the machine profile. We recommend that you use an Azure Resource Manager (ARM) template spec with extensions as the machine profile instead.

In this blog post, I’ll show you how to add an Azure VM extension to an ARM template spec and how to use it as a machine profile in MCS catalog creation. This will enable you to provision catalog machines with Azure VM extensions installed.

Adding an Extension

In this example, we’ll add Custom Script Extension that downloads and runs a PowerShell script to our template spec. The extension page for Custom Script Extension for Windows has a section — Property Values — that shows all the available settings you can add to the extension.

1. Start with an ARM template spec on the Azure portal. You can create this by selecting a VM and its associated network interface (NIC) and selecting Export Template. Because MCS does not support the use of parameters with machine profile, the “Include Parameters” option should be unselected. You can then add the template spec to your Azure library by clicking “Add to Library.”

2. Locate the new template spec in your Azure library and create a new version. This allows us to add the new extension to the template spec.

3. In the existing template spec, find the “resources” section and add the JSON for the new extension at the end (in the area highlighted below). For this example, the following JSON code block defines a Custom Script Extension with two settings added: “fileUris” to provide the location of a PowerShell script and “commandToExecute” to execute the script.

{
    "apiVersion": "2018-06-01",
    "type": "Microsoft.Compute/virtualMachines/extensions",
    "name": "vda-server/TestExtension",
    "location": "eastus",
    "dependsOn": [
        "[resourceId('Microsoft.Compute/virtualMachines', 'vda-server')]"
    ],
    "properties": {
        "publisher": "Microsoft.Compute",
        "type": "CustomScriptExtension",
        "typeHandlerVersion": "1.10",
        "autoUpgradeMinorVersion": true,
        "settings": {
            "fileUris": [
                "https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorial-vm-extension/installWebServer.ps1
            ],
            "commandToExecute": "powershell.exe -ExecutionPolicy Unrestricted -File installWebServer.ps1"
        }
    }
}

4. Review and save the new template spec version.

You can find the format of the JSON that must be added for extensions here. Depending on which extension is being used, there are also extension-specific settings that can be provided. The individual extension pages here contain the settings that are specific to each extension.

Provisioning a Catalog

After saving the template spec version, it will be available to select during catalog creation. You will also need to add the extension to the allowlist if not done already.

1. Add the extension to the extension allowlist. This is done using the Add-ProvMetadataConfiguration PowerShell command. For the above example, the extension type is “CustomScriptExtension,” so the “ConfigurationValue” should be set to that:

Add-ProvMetadataConfiguration -PluginType “AzureRM” -ConfigurationName “Extension” -ConfigurationValue “CustomScriptExtension”

2. On the “Master Image” step of catalog creation, check the box next to “Use a machine profile.” Then, click “Select a machine profile,” which will allow us to search for the template spec that we just created.

3. Find the resource group containing your template spec, and select the version that contains the newly added extensions. In this example, we would select version 2 of ExtensionsTemplate.

4. Proceed with catalog creation as normal. The new catalog machines will now have the Custom Script Extension that we added to the template spec.

Learn More

Adding Azure VM extensions to your machine catalogs is a powerful tool that can improve both the experience for users and admins. We encourage you to start exploring the possibilities that extensions bring to your machine catalogs today. For more information on creating Microsoft Azure catalogs, check out our product documentation.