Bash Shell Script to Start/Stop/Deallocate/Show Multiple Azure Virtual Machines

Note: To Start/Stop/Deallocate/Show any Virtual Machine in Azure, the user need to have at least Contributor role on that Azure Subscription.

Step 1: Create a new .rc file with Azure Subscription Name, this is the file to mention all the multiple virtual machines names.

# Enter the Virtual Machines Names
vm_names=(“vm01” “vm02” "vm03")
  • First, need to set Azure Subscription using az CLI command from the list of subscriptions with our ID.
  • Create AZ_ACCOUNT variable to get the Azure Subscription name for <subscription_name>.rc file.
  • Then declare the . AZ_ACCOUNT.rc file for getting the Virtual Machines Names.
  • Now have to know the Resource Group name to start/stop/deallocate or show the Virtual Machines.
  • Create new file VM_LIST_FILE for all the values inside the “/tmp/$AZ_ACCOUNT.vm.list”, this is used to copy all the details for the Virtual Machines using az CLI command: az vm list — output table > “$VM_LIST_FILE”.
  • Now select action needs to be performed on each Individual Virtual machine.
Shell Script Code to Start/Stop/Deallocate/Show Virtual Machine



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CloudTech Point

CloudTech Point

DevOps & Cloud Engineering | Unix/Linux | Development and Information Technology Tips & Solutions | Investing Tips | Stock Market