Search code examples
azurepowershellazure-virtual-network

Get virtual network details from Virtual Network gateway in Azure


How can I get virtual network name from Virtual network gateway in Azure. It is not listed as a property. enter image description here


Solution

  • How can I get virtual network name from Virtual network gateway in Azure. It is not listed as a property.

    To get virtual network name from Virtual network gateway.

    Here is the PowerShell command.

        $resourceGroupName = "<RG-NAMe>"
        $gatewayName = "<Gateway-Name>"
        $gateway = Get-AzVirtualNetworkGateway -ResourceGroupName $resourceGroupName -Name $gatewayName
        foreach ($ipConfig in $gateway.IpConfigurations) {
            $virtualNetworkName = ($ipConfig.Subnet.Id -split '/')[-3]
            Write-Output "Virtual Network Name: $virtualNetworkName"
        }
    

    Output:

    enter image description here

    Reference: Get-AzVirtualNetworkGateway