vm_name="myvm" vm_rg="myrg" nic_id=`az vm nic list -g $vm_rg --vm-name $vm_name --query "[].{id:id}"` # echo to make sure we're getting the right value. echo $nic_id