Azure CLI

%3CLINGO-SUB%20id%3D%22lingo-sub-1958916%22%20slang%3D%22en-US%22%3EAzure%20CLI%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1958916%22%20slang%3D%22en-US%22%3E%3CP%3ENeed%20some%20help.%26nbsp%3B%20%26nbsp%3BNew%20at%20Azure%20CLI...%26nbsp%3B%3C%2FP%3E%3CP%3Eis%20there%20a%20way%20to%20run%20the%20az%20cli%20command%20%22below%22%20from%20Azure%20Cloud%20Shell%20as%20a%20.sh%20script.%26nbsp%3B%20%26nbsp%3Bit's%20a%20pretty%20Also%2C%20is%20there%20a%20way%20for%20it%20to%20prompt%20for%20the%20destination%20subscription%20ID%3F%26nbsp%3B%20I%20ask%20this%20because%20i%20would%20be%20deploying%20this%20to%20one%20of%20many%20subscriptions%20as%20a%20one%20time%20thing.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Escript%3CBR%20%2F%3Eaz%20vm%20create%20-n%20vrossvm%20-g%20DevRG%20--vnet-name%20DevNetwork%20--subnet%20AppTierSubnet%20--nsg%20APPTierNSG%20--public-ip-address%20'%22%22'%20--location%20eastus%20--admin-username%20admin%20--admin-password%20password123%20--size%20Standard_DS2_v3%20--subscription%20mytsubscription%20--image%20%2Fsubscriptions%2Fxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxx2%2FresourceGroups%2Fsharedrg%2Fproviders%2FMicrosoft.Compute%2Fgalleries%2Fsharedimage%2Fimages%2Fwin10golddisk%2Fversions%2F1.0.0%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1959006%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20CLI%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1959006%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F891923%22%20target%3D%22_blank%22%3E%40jimreid3%3C%2FA%3E%3C%2FP%3E%3CP%3Efound%20a%20solution.%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3E%23!%2Fbin%2Fbash%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Edeclare%20SUBSCRIPTION%3D%22%22%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Ewhile%20getopts%20%22%3Ag%3A%22%20arg%3B%20do%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Ecase%20%22%24%7Barg%7D%22%20in%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Eg)%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3ESUBSCRIPTION%3D%24%7BOPTARG%7D%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3E%3B%3B%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Eesac%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Edone%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CFONT%20color%3D%22%23800000%22%3E%3CSTRONG%3Eshift%20%24((OPTIND-1))%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3E%23Prompt%20for%20parameters%20is%20some%20required%20parameters%20are%20missing%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eif%20%5B%5B%20-z%20%22%24SUBSCRIPTION%22%20%5D%5D%3B%20then%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eecho%20%22Your%20subscription%20ID%20can%20be%20looked%20up%20with%20the%20CLI%20using%3A%20az%20account%20show%20--out%20json%20%22%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eecho%20%22Enter%20your%20subscription%20ID%3A%22%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eread%20SUBSCRIPTION%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3E%5B%5B%20%22%24%7BSUBSCRIPTION%3A%3F%7D%22%20%5D%5D%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Efi%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eecho%20'creating%20your%20resource%20group'%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3Eaz%20group%20create%20--name%20DevRG%20--subscription%20%24SUBSCRIPTION%20-l%20eastus%3C%2FFONT%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3Esleep%3C%2FSPAN%3E%20%3CSPAN%3E5%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eecho%3C%2FSPAN%3E%20%3CSPAN%3E'creating%20vm%20workstation'%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3Eaz%20vm%20create%20%3C%2FSPAN%3E%3CSPAN%3E-n%3C%2FSPAN%3E%3CSPAN%3E%20myvm%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E-g%3C%2FSPAN%3E%3CSPAN%3E%20DevRG%20%3C%2FSPAN%3E%3CSPAN%3E--vnet-name%3C%2FSPAN%3E%3CSPAN%3E%20DevNetwork%20%3C%2FSPAN%3E%3CSPAN%3E--subnet%3C%2FSPAN%3E%3CSPAN%3E%20AppSubnet%20%3C%2FSPAN%3E%3CSPAN%3E--nsg%3C%2FSPAN%3E%3CSPAN%3E%20APPNSG%20%3C%2FSPAN%3E%3CSPAN%3E--public-ip-address%3C%2FSPAN%3E%20%3CSPAN%3E%22%22%3C%2FSPAN%3E%20%3CSPAN%3E--location%3C%2FSPAN%3E%3CSPAN%3E%20eastus%20%3C%2FSPAN%3E%3CSPAN%3E--admin-username%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3Badmin%20%3C%2FSPAN%3E%3CSPAN%3E--admin-password%3C%2FSPAN%3E%3CSPAN%3E%20password123%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3E--size%3C%2FSPAN%3E%3CSPAN%3E%20Standard_DS3_v2%20%3C%2FSPAN%3E%3CSTRONG%3E%3CFONT%20color%3D%22%23800000%22%3E--subscription%20%24SUBSCRIPTION%3C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C%2FDIV%3E%3C%2FLINGO-BODY%3E
New 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'