Edit

Share via


Manage Azure VM Applications

This article talks about how to view, update, and delete published VM Application in Azure Compute Gallery. It then talks about how to view, monitor, update, and delete deployed VM application resource on Azure Virtual Machine (VM) or Virtual Machine Scale Sets.

This section explains about how to view, update, and delete published VM Applications in Azure Compute Gallery.

View published VM Applications

To view the properties of a published VM Application in the Azure portal:

  1. Sign in to the Azure portal.
  2. Search for Azure Compute Gallery.
  3. Select the gallery that contains your VM Application.
  4. Click the VM Application Name you want to view.
  5. The Overview/Properties blade displays information about the VM Application.
  6. The Overview/Versions blade displays all published versions and its basic properties like Target Regions, Provisioning state, and Replication state.
  7. Select a specific version to view all its details.

Screenshot showing VM Application properties & all versions in the Azure portal.

Screenshot showing VM Application version properties in the Azure portal.

View published VM applications using Azure Resource Graph

Azure resource graph query can be used to view all published VM applications and their properties across all compute galleries. It provides a programmatic way to view application inventory, and their properties at high scale. Use this method for integrating with dashboards and custom reports.

View list of all compute galleries

resources
| where type == "microsoft.compute/galleries"
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| extend provisioningState = properties["provisioningState"]
| extend permissions = properties["sharingProfile"]["permissions"]
| extend communityGalleryInfo = properties["sharingProfile"]["communityGalleryInfo"]
| project subscriptionId, resourceGroup, location, name, provisioningState, permissions, communityGalleryInfo

View list of all published VM Applications across all galleries

resources
| where subscriptionId == "85236c53-92ad-4e66-97a4-8253a5246b99"
| where type == "microsoft.compute/galleries/applications"
| extend OSType = properties["supportedOSType"]
| extend description = properties["description"]
| extend endOfLifeDate = properties["endOfLifeDate"]
| parse id with  "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName  
| project subscriptionId, resourceGroup, location, gallaryName, name, OSType, description

View list of all published VM Application Versions across all applications and galleries

resources
| where type == "microsoft.compute/galleries/applications/versions"
| project subscriptionId, resourceGroup, id, location, properties
| parse id with  "/subscriptions/" SubId "/resourceGroups/" rgName "/providers/Microsoft.Compute/galleries/" gallaryName "/applications/" appName "/versions/" versionNumber 
| extend provisioningState = properties["provisioningState"]
| extend publishingProfile = properties["publishingProfile"]
| extend storageAccountType = publishingProfile["storageAccountType"]
| extend scriptBehaviorAfterReboot = publishingProfile["settings"]["scriptBehaviorAfterReboot"]
| extend packageFileName = publishingProfile["settings"]["packageFileName"]
| extend configFileName = publishingProfile["settings"]["configFileName"]
| extend mediaLink = publishingProfile["source"]["mediaLink"]
| extend defaultConfigurationLink = publishingProfile["source"]["defaultConfigurationLink"]
| extend excludeFromLatest = publishingProfile["excludeFromLatest"]
| extend targetRegions = publishingProfile["targetRegions"]
| extend replicaCount = publishingProfile["replicaCount"]
| extend publishedDate = publishingProfile["publishedDate"]
| extend installScript = publishingProfile["manageActions"]["install"]
| extend removeScript = publishingProfile["manageActions"]["remove"]
| extend safetyProfile = properties["safetyProfile"]
| extend allowDeletionOfReplicatedLocations = safetyProfile["allowDeletionOfReplicatedLocations"]
| project-away safetyProfile, publishingProfile, SubId, rgName, id, properties

Update published VM Application

Note

Not all properties of a published VM Application or VM Application version can be updated. For a complete list of updatable properties, refer to the VM Application resource and VM Application version resource schema.

Update VM Application resource:

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}?api-version=2024-03-03

Body
{
    "properties": {
        "description": "Updated description",
        "endOfLifeDate": "2026-12-31T00:00:00Z",
        "eula": "Updated EULA text",
        "privacyStatementUri": "https://contoso.com/privacy",
        "releaseNoteUri": "https://contoso.com/release-notes"
    }
}

Update VM Application version resource:

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{galleryApplicationName}/versions/{galleryApplicationVersionName}?api-version=2024-03-03

Body
{
    "properties": {
        "publishingProfile": {
            "targetRegions": [
                {
                    "name": "eastus",
                    "regionalReplicaCount": 2,
                    "storageAccountType": "Standard_LRS"
                },
                {
                    "name": "westus",
                    "regionalReplicaCount": 1,
                    "storageAccountType": "Standard_LRS"
                }
            ],
            "excludeFromLatest": false
        }
    }
}

To delete the VM Application resource, you need to first delete all its versions. Deleting the application version causes deletion of the application version resource from Azure Compute Gallery and all its replicas. The application blob in Storage Account used to create the application version is unaffected.

Warning

  • Deleting the application version causes subsequent PUT operations on VMs using that version to fail. To prevent this failure, use latest keyword as the version number in the applicationProfile instead of hard coding the version number .

  • Deleting the VM application that is deployed on any VM or Virtual Machine Scale Sets causes subsequent PUT operations on these resources to fail (for example, update, scale, or reimage). Before deleting, ensure all VMs/Virtual Machine Scale Sets instances stop using the application by removing it from their applicationProfile.

  • To prevent accidental deletion, set safetyProfile/allowDeletionOfReplicatedLocations to false while publishing the version and apply an Azure Resource Manager lock (CanNotDelete or ReadOnly) on the VM application resource.

  1. Sign in to the Azure portal.
  2. Search for Azure Compute Gallery and open the target gallery.
  3. Select the VM application you want to remove.
  4. Select one or more versions, which you want to delete.
  5. To delete the VM application, first delete all the versions. Then click delete (on top of the blade).
  6. Monitor Notifications for completion. If deletion is blocked, remove any locks and ensure no VM or Virtual Machine Scale Sets references the application.

Screenshot showing deletion of a VM application and its versions in the Azure portal.

Manage deployed VM Application on Azure VM and Virtual Machine Scale Sets

This section explains how to view deployed application details and monitor deployed applications across infrastructure. It also talks about how to update and delete deployed VM Applications on Azure VMs and Virtual Machine Scale Sets.

View deployed VM Applications & their state

Azure uses VMAppExtension to deploy, monitor, and manage VM Applications on the VM. Therefore, provisioning state of the deployed VM Application is described in the status of the VMAppExtension.

To show the VM application status, go to the Extensions + applications tab under settings and check the status of the VMAppExtension:

Screenshot showing VM application status.

To show the VM application status for a Virtual Machine Scale Sets, go to the Azure portal Virtual Machine Scale Sets page. In the Instances section, select one of the instances. Then go to Extensions + Applications tab under settings and check the status of the VMAppExtension:

Screenshot showing Virtual Machine Scale Sets application status.

View logs of application installation using Run command

When Azure VM Applications downloads and installs the application on Azure VM or Virtual Machine Scale Sets, it pipes all stdout results to stdout file within the application repository. Customers can enable verbose logging for the application installation and write custom logs using the installScript. Customers can then manually check the stdout and stderr file or use Runcommand to get the file content.

Use the following PowerShell script in your managed run command. Update the appName and appVersion variables for your application

$appName = "vm-application-name"        # VM Application definition name
$appVersion = "1.0.0"                   # VM Application version name

$VMAppManagerVersion = "1.0.16"         # Version of the VMApplicationManagerWindows extension on the VM
$StdoutFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stdout"
$StderrFilePath = "C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\$VMAppManagerVersion\Downloads\$appName\$appVersion\stderr"

Write-Host "`n=== Contents of stdout ==="
Get-Content -Path $StdoutFilePath

Write-Host "`n=== Contents of stderr ==="
Get-Content -Path $StderrFilePath

Execute the run command using the scripts and get the application install logs.

  1. Open the Azure portal and navigate to your VM.
  2. Under Operations, select Run command.
  3. Choose RunPowerShellScript from the list.
  4. Enter your PowerShell script in the editor.
  5. Select Run to execute the script.
  6. View the output in the Output section. If the script fails, check the Error section for details.

For more information, see Run PowerShell scripts in your Windows VM by using Run Command.

View all deployed VM applications using Azure Resource Graph

Azure resource graph query can be used to view all deployed VM applications and their properties across all VMs and Virtual Machine Scale Sets. It provides a programmatic way to view application inventory, state, and deployed versions at high scale. Use this method for integrating with dashboards and custom reports.

resources
| where type == "microsoft.compute/virtualmachines" or type == "microsoft.compute/virtualmachinescalesets"
| where properties has "applicationProfile"
| extend resourceType = iff(type == "microsoft.compute/virtualmachines", "VM", "VMSS")
| extend applications = iff(resourceType == "VM", parse_json(properties["applicationProfile"]["galleryApplications"]), parse_json(properties["virtualMachineProfile"]["applicationProfile"]["galleryApplications"]))
| mv-expand applications
| extend enableAutomaticUpgrade = applications["enableAutomaticUpgrade"]
| extend packageReferenceId = applications["packageReferenceId"]
| extend treatFailureAsDeploymentFailure = applications["treatFailureAsDeploymentFailure"]
| parse packageReferenceId with "/subscriptions/" publisherSubcriptionId "/resourceGroups/" publisherResourceGroup "/providers/Microsoft.Compute/galleries/" galleryName "/applications/" appName "/versions/" version
| project tenantId, subscriptionId, resourceGroup, resourceName = name, type, location, appName, version, enableAutomaticUpgrade, treatFailureAsDeploymentFailure, galleryName, publisherSubcriptionId, publisherResourceGroup, properties

Audit required VM Application using Azure Policy

Azure Policy helps enforce governance by auditing whether required VM applications are deployed across your VMs and Virtual Machine Scale Sets. You can create and assign custom policies to check compliance and ensure that specific applications are present on your infrastructure.

For step-by-step instructions on how to audit VM application deployment using Azure Policy, see Audit required VM applications using Azure Policy.

Update the deployed VM Application

To update a deployed VM application, modify the applicationProfile to reference a newer version or change deployment settings such as treatFailureAsDeploymentFailure or order.

Update the VM application version or settings on a single VM:

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}?api-version=2024-03-03

Body
{
    "properties": {
        "applicationProfile": {
            "galleryApplications": [
                {
                    "packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion}",
                    "treatFailureAsDeploymentFailure": true,
                    "enableAutomaticUpgrade": true
                }
            ]
        }
    }
}

Update VM application on a Virtual Machine Scale Sets (model):

PATCH
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}?api-version=2024-03-03

Body
{
    "properties": {
        "virtualMachineProfile": {
            "applicationProfile": {
                "galleryApplications": [
                    {
                        "packageReferenceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/galleries/{galleryName}/applications/{applicationName}/versions/{newVersion | latest}",
                        "treatFailureAsDeploymentFailure": true,
                        "order": 2
                    }
                ]
            }
        }
    }
}

Apply the change to existing Virtual Machine Scale Sets instances (required when upgradePolicy.mode is Manual):

POST
https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmssName}/updateInstances?api-version=2024-03-03

Body
{
    "instanceIds": ["*"]
}

Tip

Use latest as the version identifier in packageReferenceId to automatically deploy the newest published version without manually updating deployments.

Remove the VM Application from Azure VM or Virtual Machine Scale Sets

  1. Open the Azure portal and go to the target virtual machine (VM) or Virtual Machine Scale Sets.
  2. In Settings, select Extensions + applications, then select the VM Applications tab.
  3. Click uninstall button on the VM Application and Save.
  4. Track progress in Notifications or check Instance view for the VMAppExtension status.

Screenshot showing how to Uninstall VM application from a VM.

Next steps