What is the process to upgrade existing Azure VM agent after provisioning

Glenn Hunter 125 Reputation points Microsoft Employee
2024-04-24T07:02:47.7733333+00:00

 The customer is asking for the documented process on how to update Azure VM Agent in Azure after the VM is deployed. The Customer has a lot of different versions of Azure VM agent on their servers that need upgrading. MS Documentation explains detail for automatic/manual install of VM agent at time of provisioning: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-windows#upgrade-the-azure-windows-vm-agent

But not about upgrading of an existing Azure VM agent.?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,160 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anveshreddy Nimmala 2,465 Reputation points Microsoft Vendor
    2024-04-24T08:39:19.23+00:00

    Hello Glenn Hunter,

    Use PowerShell to inventory the current version of the Azure VM Agent installed across all VMs.

    $Report = [System.Collections.Generic.List[Object]]::new()
        $vms = $null
        $vms = Get-azVm -Status
        Foreach ($vm in $vms){
            $obj = [PSCustomObject][ordered]@{
                    "Server Name" = $vm.Name
                    "OS" = $vm.StorageProfile.ImageReference.offer
                    "OS Sku" = $vm.StorageProfile.ImageReference.sku
                    "OS Name" = $vm.OsName
                    "OS Version" = $vm.OsVersion
                }
        $report.Add($obj)
        }
    $Report | Export-CSV C:\temp\ArchieVM_Status.csv
    

    This can be run against any subscription to retrieve Azure VMs and their corresponding operating systems.

    NOTE: The OS Name and OS Version will not be populated if the VM is turned off/deallocated.

    Download the latest version of the VM Agent from the https://github.com/Azure/WindowsVMAgent.

    Deploy this via automation tools (like Azure Automation, PowerShell, Desired State Configuration (DSC), or Group Policy) to manage updates across multiple VMs efficiently.

    deployment using powershell script

    # Login and set context
    Connect-AzAccount
    $subscriptionId = "your-subscription-id"
    Set-AzContext -SubscriptionId $subscriptionId
    # Get all VMs in the subscription
    $vms = Get-AzVM
    # Loop through each VM
    foreach ($vm in $vms) {
        # Get the status of each VM
        $vmStatus = Get-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Status
        # Check if the VM Agent is outdated
        if ($vmStatus.Statuses.DisplayStatus -contains "VM Agent is outdated") {
            # Output the VM name and status
            Write-Output "VM Agent is outdated on VM: $($vm.Name)"
            # Restart the VM to trigger agent update - Uncomment the next line to enable restart
            # Restart-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name -Force
            # Alternatively, you can inform the user to manually update or set auto-update settings
            Write-Output "Please update the VM Agent manually or ensure that auto-update is enabled."
        }
        else {
            # Output that the VM is up to date
            Write-Output "VM Agent is up to date on VM: $($vm.Name)"
        }
    }
    

    Check with this documentation if it helps you

    https://learn.microsoft.com/en-us/azure/virtual-machines/windows-in-place-upgrade

    Hope this helps you

    If an answer has been helpful, please consider accepting the answer to help increase visibility of this question for other members of the Microsoft Q&A community. If not, please let us know what is still needed in the comments so the question can be answered. Thank you for helping to improve Microsoft Q&A!

    712bcc84-b098-4ea0-a30a-1c7e2b40d63c

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Alex Burlachenko 810 Reputation points
    2024-04-24T08:03:11.4366667+00:00

    Hi Glenn,

    The process of upgrading the Azure Virtual Machine (VM) Agent after a VM has been deployed is not explicitly documented in Microsoft documentation. However, there are some general steps that can be followed to upgrade the VM Agent:

    1. Check the current version of the Azure VM Agent: This can be done by checking the Azure portal under the properties of the VM to see the current version installed.
    2. Download the latest version of the VM Agent: The latest version can be downloaded from the official Microsoft download center.
    3. Install the latest VM Agent version: After downloading, the latest version can be installed on the VMs. The installation process should be similar to the initial installation, and VMs may need to be restarted after the upgrade.Verify the installation: After the installation process, you can check if the latest version of the Azure Virtual Machine Agent has been correctly installed on your virtual machines. You can do this by verifying the version of the agent in the Azure Portal under the properties of your virtual machine.

    It's important to note that you should update the "AllowExtensionOperations" option after manually installing the Azure Windows Virtual Machine Agent on a virtual machine that was deployed from a template without the ProvisionVMAgent option enabled.

    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members. 

    1 person found this answer helpful.
    0 comments No comments