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:
- Azure CLI
- Azure PowerShell
- 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:
- PowerShell Cmdlet for updating extensions:
Check the link for more details: https://learn.microsoft.com/en-us/powershell/module/az.connectedmachine/update-azconnectedmachineextensionUpdate-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 }\""}'
- Azure CLI – best recommended for Automation for scripting, pipelines, and IaC.
Check the link for more details: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-vm-extensions-cliaz 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\""}'
- ARM Template or Bicep suitable best for declarative full-stack deployments.
Check the link for more details: https://learn.microsoft.com/en-us/azure/azure-arc/servers/manage-vm-extensions-portal{ "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\"" } } }
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.