Hello arun kumar
Welcome to Microsoft Q&A Platform, thanks for posting your query here.
Adding to previous response from JimmySalian, Yes, you can use Azure CLI or PowerShell to push commands to multiple Linux VMs in Azure. One way to do this is by using Azure Virtual Machine Extensions. Extensions are small applications that provide post-deployment configuration and automation tasks on Azure VMs. You can use extensions to install and configure software, manage users and passwords, and execute scripts.
To push commands to multiple Linux VMs, you can create a custom script extension that runs your commands on the VMs**.** You can use Azure CLI or PowerShell to create and manage extensions.
Here's an example of how to create a custom script extension using Azure CLI:
az vm extension set \
--resource-group myResourceGroup \
--vm-name myVM \
--name customScript \
--publisher Microsoft.Azure.Extensions \
--version 2.0 \
--settings '{"fileUris":["https://mystorageaccount.blob.core.windows.net/scripts/myscript.sh"],"commandToExecute":"./myscript.sh"}'
This command creates a custom script extension that downloads a script from a storage account and executes it on the VM. You can use this command to create the extension on multiple VMs by running it in a loop or a script.
You can also use Azure Automation to run PowerShell scripts on multiple VMs. Azure Automation is a cloud-based automation and configuration service that provides a way to manage your resources at scale. You can use Azure Automation to run PowerShell scripts on Azure VMs, on-premises servers, and other cloud platforms.
Here's an example of how to run a PowerShell script on multiple VMs using Azure Automation:
- Create an Azure Automation account and configure it to manage your VMs.
- Create a PowerShell script that contains the commands you want to run on the VMs.
- Create an Azure Automation runbook that runs the PowerShell script.
- Schedule the runbook to run on a regular basis or trigger it manually.
When the runbook runs, it executes the PowerShell script on the VMs you specified. You can use Azure Automation to manage and monitor the execution of the script.
Ref: https://learn.microsoft.com/en-us/azure/automation/learn/automation-tutorial-runbook-textual
https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows
Hope this helps.