Azure Extension

Mohan Krishna T Sreeramulu 280 Reputation points Microsoft External Staff Moderator
2025-05-09T05:30:53.07+00:00

Is there any way to add VM extensions to Azure Local / Azure Arc VMs through Azure PowerShell or Azure CLI?

I'm trying to automate deploying and managing Azure Arc VMs entirely via IaC. Deployments have been fairly straightforward with Azure CLI. However, I'm at a loss trying to add extensions - like a Custom Script extension - without the use of the Portal.

Azure Arc
Azure Arc
A Microsoft cloud service that enables deployment of Azure services across hybrid and multicloud environments.
525 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 22,031 Reputation points Volunteer Moderator
    2025-05-09T10:21:50.8466667+00:00

    Hello Mohan Krishna T Sreeramulu,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you would like to know method to add VM extensions to Azure Local or Azure Arc VMs through Azure PowerShell or Azure CLI.

    Yes, you can add VM extensions to Azure Arc-enabled servers such as non-Azure VMs connected to Azure via Azure Arc or on-prem using these three methods:

    1. Azure CLI
    2. Azure PowerShell
    3. ARM templates

    However, you will need to put into consideration the best practices:

    • Azure CLI for automation, scripting, and pipelines,
    • Azure PowerShell for PowerShell-centric environments,
    • ARM Templates for declarative IaC and CI/CD pipelines

    Three of them now support create and update. The below is a code snippet example for each listed above:

    1. PowerShell Cmdlet for updating extensions:
         Update-AzConnectedMachineExtension `
           -ResourceGroupName "myResourceGroup" `
           -MachineName "myMachineName" `
           -Name "CustomScriptExtension" `
           -Publisher "Microsoft.Compute" `
           -Type "CustomScriptExtension" `
           -TypeHandlerVersion "1.10" `
           -Settings '{"commandToExecute":"powershell.exe -c \"Get-Process | Where-Object { $_.CPU -gt 10000 }\""}'
      
      Check the link for more details: https://learn.microsoft.com/en-us/powershell/module/az.connectedmachine/update-azconnectedmachineextension
    2. Azure CLI – best recommended for Automation for scripting, pipelines, and IaC.
         az connectedmachine extension create \
           --machine-name "myMachine" \
           --resource-group "myResourceGroup" \
           --location "eastus" \
           --name "CustomScriptExtension" \
           --publisher "Microsoft.Compute" \
           --type "CustomScriptExtension" \
           --type-handler-version "1.10" \
           --settings '{"commandToExecute":"powershell.exe -c \"Get-Process\""}'
      
      Check the link for more details: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-vm-extensions-cli
    3. ARM Template or Bicep suitable best for declarative full-stack deployments.
         {
           "type": "Microsoft.HybridCompute/machines/extensions",
           "apiVersion": "2023-03-15",
           "name": "[concat(parameters('machineName'), '/CustomScriptExtension')]",
           "location": "[parameters('location')]",
           "properties": {
             "publisher": "Microsoft.Compute",
             "type": "CustomScriptExtension",
             "typeHandlerVersion": "1.10",
             "settings": {
               "commandToExecute": "powershell.exe -c \"Get-Process\""
             }
           }
         }
         
      
      Check the link for more details: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-vm-extensions-portal

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.