BASH script to start or deallocate all VMs in Resource Group
For the first time here, I will use Azure CLI 2.0. It is written in Python and You can install it with pip install azure-cli
.
First of all we need to login to our Azure account. If You are using MS Account there will be an interactive login procedure. You can also use Azure AD credentials or Service Principal for Your application/script (the same way as described here.
az login
Next, we need to set subscription we want to use (if there is more than one associated with Your account).
az account set --subscription subscription-id
Replace subscription-id with Your's subscription of choice ID.
And now let's deallocate all VMs in Resource Group of choice:
rg=rgname; az vm list -g $rg -o tsv | for i in $(awk -F