Azure CLI

Copper Contributor

Need some help.   New at Azure CLI... 

is there a way to run the az cli command "below" from Azure Cloud Shell as a .sh script.   it's a pretty Also, is there a way for it to prompt for the destination subscription ID?  I ask this because i would be deploying this to one of many subscriptions as a one time thing.  

 

script
az vm create -n vrossvm -g DevRG --vnet-name DevNetwork --subnet AppTierSubnet --nsg APPTierNSG --public-ip-address '""' --location eastus --admin-username admin --admin-password password123 --size Standard_DS2_v3 --subscription mytsubscription --image /subscriptions/xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx2/resourceGroups/sharedrg/providers/Microsoft.Compute/galleries/sharedimage/images/win10golddisk/versions/1.0.0

1 Reply

@jimreid3

found a solution.

#!/bin/bash

declare SUBSCRIPTION=""

while getopts ":g:" arg; do
case "${arg}" in
g)
SUBSCRIPTION=${OPTARG}
;;

esac
done

shift $((OPTIND-1))


#Prompt for parameters is some required parameters are missing
if [[ -z "$SUBSCRIPTION" ]]; then
echo "Your subscription ID can be looked up with the CLI using: az account show --out json "
echo "Enter your subscription ID:"
read SUBSCRIPTION
[[ "${SUBSCRIPTION:?}" ]]
fi

echo 'creating your resource group'

az group create --name DevRG --subscription $SUBSCRIPTION -l eastus

sleep 5
echo 'creating vm workstation'
az vm create -n myvm -g DevRG --vnet-name DevNetwork --subnet AppSubnet --nsg APPNSG --public-ip-address "" --location eastus --admin-username admin --admin-password password123 --size Standard_DS3_v2 --subscription $SUBSCRIPTION --image /subscriptions/yyyyyyyyy-yyyyy-yyyy-yyyyyyyyyy/resourceGroups/sharedrg/providers/Microsoft.Compute/galleries/sharedimage/images/win10golddisk/versions/1.0.0

sleep 30


echo 'end'