Start and stopping all Virtual Machines on a Resource Group

Start and stopping all Virtual Machines on a Resource Group

Check how you can build a script to start or stop all virtual machines in a resource group in azure using powershell.Some tasks on azure are easier if we automate them. The Azure Portal provides us the cloud shell, which we can use for this kind of automation. I was making some experiences with SQL Server Always On, so I created three VMs inside a resouce group. Every time I want to start some experiment I need to start all three VMs and, in the end, stop all three again.

Some tasks on azure are easier if we automate them. The Azure Portal provides us the cloud shell, which we can use for this kind of automation.

I was making some experiences with SQL Server Always On, so I created three VMs inside a resouce group. Every time I want to start some experiment I need to start all three VMs and, in the end, stop all three again.

Creating a Powershell script

This is not a complex task, but it’s not something we would like to type every time. Using Azure CLI, we have the following instructions available:

az account set: Choose the default subscription. If you have more than a single subscription, you would like

az vm list : List all VM’s and it’s possible to filter by resource group

az vm start/stop: Start or stop the vm

In order to start or stop the VMs, we can combine the CLI statements using powershell. They will be like this:

On these examples we are using the AZ VM LIST to retrieve the list of Ids of the VMs and use this list to start or stop the VMs.

–query extracts only the .id from the JSON object returned by the LIST statement

-o tsv specifies the format, tab separated values, for the Ids

We can prepare the script to receive two parameters, the operation we will execute (start/stop) and the name of the resource group. The first line of the script will be like this:

blogs python azure cli

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Create, Build, Deploy and Configure an Azure Function with Azure DevOps and Azure CLI

How to create, build, deploy and configure an Azure Function using Azure DevOps, Azure CLI and Powershell.

Create, Build, Deploy and Configure an Azure App Service with Azure DevOps and Azure CLI

This post shows how to create, build, deploy and configure an Azure App Service using Azure DevOps, Azure CLI and Powershell.

Python Tricks Every Developer Should Know

In this tutorial, you’re going to learn a variety of Python tricks that you can use to write your Python code in a more readable and efficient way like a pro.

How to Remove all Duplicate Files on your Drive via Python

Today you're going to learn how to use Python programming in a way that can ultimately save a lot of space on your drive by removing all the duplicates. We gonna use Python OS remove( ) method to remove the duplicates on our drive. Well, that's simple you just call remove ( ) with a parameter of the name of the file you wanna remove done.

Demo: Configure Azure SQL with Azure CLI | Azure SQL for beginners (Ep. 17)

In this video, see how to configure your Azure SQL connectivity leveraging the Azure CLI and PowerShell notebooks in Azure Data Studio. For the full Azure SQ...