Forum Discussion
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 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
- jimreid3Copper Contributor
found a solution.
#!/bin/bashdeclare SUBSCRIPTION=""while getopts ":g:" arg; docase "${arg}" ing)SUBSCRIPTION=${OPTARG};;esacdoneshift $((OPTIND-1))#Prompt for parameters is some required parameters are missingif [[ -z "$SUBSCRIPTION" ]]; thenecho "Your subscription ID can be looked up with the CLI using: az account show --out json "echo "Enter your subscription ID:"read SUBSCRIPTION[[ "${SUBSCRIPTION:?}" ]]fiecho 'creating your resource group'az group create --name DevRG --subscription $SUBSCRIPTION -l eastussleep 5echo '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.0sleep 30echo 'end'