As a developer sometimes I have to use several virtual machines to develop my projects.
My machines, of course, live and run on Azure.
Every time I have to log in on Azure Portal, find the resource group, find the VM, click on "Start" and wait a few minutes to connect to my VM.
The best solution I found is using Azure CLI.
The Azure CLI is a command-line tool for managing Azure resources from Windows, Mac and Linux (Docker, WSL as well).
The current version is 2.0.76.
To install Azure CLI on Windows is very easy.
You can use this link to download the installer or you can launch this PowerShell script with administrator rights:
Invoke-WebRequest -Uri https://aka.ms/installazurecliwindows -OutFile .\AzureCLI.msi; Start-Process msiexec.exe -Wait -ArgumentList '/I AzureCLI.msi /quiet'
To install Azure CLI on Mac, you need homebrew.
From a terminal you can launch this command:
brew update && brew install azure-cli
You can find the full list of supported platform here: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
To check if Azure CLI is running and the version, you can use this command from a terminal.
At the moment my favorite terminal app is Windows Terminal
The login command is
This is an interactive method and you have to open a browser and navigate to this url: https://aka.ms/devicelogin.
Enter the authorization code displayed in the terminal and then the credentials for your Azure Tenant.
In the next terminal session you can use this tenant or you can add more tenants.
I like this feature.
To start a VM you can use the command below:
az vm start -g MyResourceGroup -n MyVm
You have to change the parameter -g (or --resource-group) with your value.
Same for -n (or --name) with the name of your VM.
You can start all VMs in a resource group with the command below.
az vm start --ids $(az vm list -g MyResourceGroup --query ".id" -o tsv)
If you don't want to wait the end of the operation, you can add the parameter --no-wait to your commands.
Command is very similar to the start command:
az vm stop -g MyResourceGroup -n MyVm
Same for the restarting command
az vm restart -g MyResourceGroup -n MyVm
With Azure CLI you can manage all resources in Azure and you can do it with cross-platform experience.
You can find the full documentation here: https://docs.microsoft.com/en-us/cli/azure
Posted on Nov 13 '19 by: