Search code examples
azurepowershellazure-virtual-network

Azure powershell - Select subproperty from resource properties


I want to select only name and Id under IPconfigurations/Subnet but can't figure out if it is possible. Please help or point me to right direction.

Here is commnad and the output.


PS C:\Users\aarora> Get-AzVirtualNetworkGateway -ResourceGroupName rg-vwan -Name as-vnet-gateway-rb-s2s


Name                            : as-vnet-gateway-rb-s2s
ResourceGroupName               : rg-vwan
Location                        : centralus
Id                              : /subscriptions/xxx/resourceGroups/rg-vwan/providers/Microsoft.Network/virtualNetworkGateways/texas-vnet-gateway-rb-s2s
Etag                            : W/"76489c17-50c5-49b5-9d65-19280e98718e"
ResourceGuid                    : e49c4f7f-3123-497e-8257-dd1f8c943e1c
ProvisioningState               : Succeeded
Tags                            :
IpConfigurations                : [
                                    {
                                      "PrivateIpAllocationMethod": "Dynamic",
                                      "Subnet": {
                                        "Id": "/subscriptions/xxx/resourceGroups/rg-vwan/providers/Microsoft.Network/virtualNetworks/vnet-am-rb-s2s/subnets/GatewaySubnet"
                                      },
                                      "PublicIpAddress": {
                                        "Id": "/subscriptions/xxx/resourceGroups/rg-vwan/providers/Microsoft.Network/publicIPAddresses/pub-ip-as-rb-s2s"
                                      },
                                      "Name": "default",
                                      "Etag": "W/\"76489c17-50c5-49b5-9d65-19280e98718e\"",
                                      "Id": "/subscriptions/xxx/resourceGroups/rg-vwan/providers/Microsoft.Network/virtualNetworkGateways/as-vnet-gateway-rb-s2s/ipConfigurations/default"
                                    }
                                  ]

Solution

  • When I tried same command, I got the same result:

    $gatewayInfo = Get-AzVirtualNetworkGateway -ResourceGroupName hedwig -Name vpn1
    

    enter image description here

    To select only name and Id under IPconfigurations/Subnet make use of below command:

    Get-AzVirtualNetworkGateway -ResourceGroupName <RGNAME> -Name <vpnNAME> | Select-Object -ExpandProperty IpConfigurations | Select-Object -Property Name, @{Name="SubnetId";Expression={$_.Subnet.Id}}
    

    enter image description here