Forum Discussion
jimreid3
Dec 05, 2020Copper Contributor
Azure CLI
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 destinat...
jimreid3
Dec 05, 2020Copper Contributor
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'