extension installation failure for azure windows vm through powershell script

Azure-learning 56 Reputation points
2022-11-14T15:01:20.097+00:00

I am trying to install "microsoft monitoring " agent through powershell script in azure windows based vms.

I am getting error "This operation cannot be performed when extension operations are disallowed. To allow, please ensure VM Agent is installed on the VM and the
osProfile.allowExtensionOperations property is true".

Please suggest how to install the vmagent and osProfile.allowExtensionOperations to yes through powershell script for windows server.

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,631 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,461 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Manu Philip 17,671 Reputation points MVP
    2022-11-14T15:22:29.06+00:00

    If the Azure VMAgent is not provisioned or installed on an Azure VM, you will not be able to use any extensions with that VM
    The error sound like VM Agent is not installed in the VM

    So, the first step is to install VMAgent and Enable VM Extensions: Check the status of the agent

    $vm = Get-AzVM -ResourceGroupName <RG name> -Name <vm name>  
    $vm.OSProfile.WindowsConfiguration.ProvisionVMAgent  
    $vm.OSProfile.AllowExtensionOperations  
    

    If you see the, result of final command as 'False', you need to download and install VMAgent in the VM. Manual installation may be necessary when you create a custom VM image that is deployed to Azure. To manually install the Windows VM Agent, download the VM Agent installer and select the latest release

    It is important to update the AllowExtensionOperations option after manually installing the VMAgent on a VM that was deployed from image without ProvisionVMAgent enable using the following scripts

    $vm.OSProfile.AllowExtensionOperations = $true  
    $vm | Update-AzVM  
    

    Once the option is enabled you should now be able to install and use extensions on the Azure VM.

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    1 person found this answer helpful.

  2. Manu Philip 17,671 Reputation points MVP
    2022-11-15T20:27:53.467+00:00

    For your info:
    260597-image.png

    So, we have to go for any other convenient way to push the agent. One of the examples is as below:

    Download and install the latest version of the agent installation package from here

    msiexec.exe /i c:\VMAgentMSI\WindowsAzureVmAgent.2.7.<version>.fre.msi /quiet /L*v c:\VMAgentMSI\msiexec.log  
    

    Update agents in VMs:

    Get-AzureVM  | where { $_.GuestAgentStatus -eq $null } | ForEach { $_.VM.ProvisionGuestAgent = $true;Update-AzureVM -VM $_.VM -Name $_.Name -ServiceName $_.ServiceName}  
    

    Check the status of the agent:

    Get-AzureVM  | select -Property ServiceName,Name,@{Name=”GuestAgentStatus”; Expression={$_.GuestAgentStatus.Status}}  
    

    ----------

    --please don't forget to upvote and Accept as answer if the reply is helpful--