With theĀ Azure CLI, use the command az vm list-ip-addresses to get the public IP address name of a virtual machine. The result will be stored in a variable.
RESOURCE_GROUP=myResourceGroup
VIRTUAL_MACHINE_NAME=myVirtualMachine
PUBLIC_IP_NAME=$(az vm list-ip-addresses \
--resource-group $RESOURCE_GROUP \
--name $VIRTUAL_MACHINE_NAME \
--query