Last active
October 9, 2017 10:58
-
-
Save itzrahulsoni/d3bb7cd7ba8dc31b2f87507fd4a3d8bd to your computer and use it in GitHub Desktop.
Manage VMs of a specific Resource Group in Azure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
AZURE_RESOURCE_GROUP='YOUR_RESOURCE_GROUP_NAME' | |
if [ $1 == "start" ]; | |
then | |
VM_NAMES=$(az vm list -g $AZURE_RESOURCE_GROUP --show-details --query "[?powerState=='VM deallocated'].{ name: name }" -o tsv) | |
for NAME in $VM_NAMES | |
do | |
echo "Starting $NAME" | |
az vm start -n $NAME -g $AZURE_RESOURCE_GROUP --no-wait | |
done | |
fi | |
if [ $1 == "stop" ]; | |
then | |
VM_NAMES=$(az vm list -g $AZURE_RESOURCE_GROUP --show-details --query "[?powerState=='VM running'].{ name: name }" -o tsv) | |
for NAME in $VM_NAMES | |
do | |
echo "Stopping $NAME" | |
az vm deallocate -n $NAME -g $AZURE_RESOURCE_GROUP --no-wait | |
done | |
fi | |
if [ $1 == "status" ]; | |
then | |
echo "Fetching Details..." | |
az vm list -g $AZURE_RESOURCE_GROUP --show-details | |
echo "Fetching Summary..." | |
echo "Power Status of all VMs" | |
echo "-----------------------" | |
az vm list -g $AZURE_RESOURCE_GROUP --show-details --query "[].{name: name, status: powerState}" -o table | |
fi | |
if [ $1 == "ip" ]; | |
then | |
az vm list -g $AZURE_RESOURCE_GROUP --show-details --query "[?powerState=='VM running'].{ name:name, ip: publicIps }" -o table | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment