Get the VNet of a Subnet with AZ cli

104 views Asked by At

I know that one way to get the VNet, is by using awk on the the id of a subnet. But what if I want to get the vnet of a subnet by using the subnet id, with az cli?

I guess I can use the az network vnet list command but I cannot figure out the proper filter that will let me search by subnets.[].id.

1

There are 1 answers

0
Sridevi On BEST ANSWER

To get the VNet name from Subnet ID via Azure CLI, you can make use of below command:

subnet_id="/subscriptions/subID/resourceGroups/rgName/providers/Microsoft.Network/virtualNetworks/VnetName/subnets/subnetName"
az network vnet list --query "[?contains(subnets[].id, '$subnet_id')].name" --output tsv

Response:

enter image description here