Start or Stop all VMs of a Resource Group in Azure

There is no direct way to start or stop all VMs of a resource group in Azure. In Azure, shutting down the server is not enough, you still pay the full compute price. It is recommended that you deallocate your servers if you want to avoid being charged while the servers are not in use. In this post, you will learn how to setup a few commands quickly. You must have Azure CLI 2.0 installed for this script to work.

Step 1: Script the common tasks

If you are using Resource Groups in Azure to organize your servers, it will make your job a lot easier in the long run. The following script has a few different parameters:

  • start: Starts all servers in the resource group
  • stop: Stops & deallocates all servers in the resource group
  • status: List detailed status of all servers in the resource group
  • ip: Shows the public IPs of all servers in the resource group

and so on...

Feel free to add more scenarios as you like. To use this script, you need to replace YOUR_RESOURCE_GROUP_NAME appropriately.

Step 2: Call script with parameters

Assuming you have created a file for the script above, and given it execute permissions using chmod 755, you can pass the arguments directly:

  • /path/to/ stop
  • /path/to/ start

and so on...

Step 3: Create Aliases (Optional)

Assuming you are using bash, you can create aliases by editing your ~/.bash_profile and pasting the code below:

alias vmstart="/path/to/vm/ start"  
alias vmstop="/path/to/vm/ stop"  
alias vmlistip="/path/to/vm/ ip"  
alias vmstatus="/path/to/vm/ status"  

Restart your terminal or source the bash_profile using source ~/.bash_profile.

Enjoy your new commands

  • vmstart : Start all VMs
  • vmstop : Stop all VMs
  • vmlistip : Show public IPs of all servers
  • vmstatus : Show detailed status of servers

You might be thinking why you would need to list public IPs of all the VMs? Well, if you deallocate your VMs the public IPs are released, and you will get new ones when you start them again. Having the IPs handy will help you update and connect to the VMs quickly without having to go to the Azure dashboard.

Hope this helps!

What next?

Well, stay tuned for upcoming articles. Say hi, share this article, leave a comment or Subscribe now to stay updated through our newsletter. Also, check out our services or contact us at for your software and consultancy requirements.


Rahul Soni

⌘⌘ Entrepreneur. Author. Geek. ⌘⌘

Kolkata, India

Subscribe to Attosol Technologies

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!