0

I want to check if a vpn gateway connection is given to a vnet through a powershell command given a vnet name.

I have created 2 vnets in 2 different resource groups and enabled peering.

twinkle hema
  • 75
  • 1
  • 11

2 Answers2

1

You can use command in following manners

First get virtual network object from azure from following command:

Vnet_object = Get-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup

"Vnet_object" will be of type "PSVirtualNetworkGateway"

Pass this object in following command and you will get virtual network gateway if it is connected to that Vnet.

Get-AzVirtualNetworkGatewayVpnClientConnectionHealth -InputObject

Link for above command: https://learn.microsoft.com/en-us/powershell/module/az.network/get-azvirtualnetworkgatewayvpnclientconnectionhealth?view=azps-2.4.0

BUD
  • 59
  • 4
  • 1
    I want to check if a gateway is connected so I will not input a gateway name and Iam doing this in Resource Manager module of powershell not AZ... – twinkle hema Jul 15 '19 at 06:13
  • same commands can be used by replacing az with AzureRM in the commands. – BUD Jul 17 '19 at 13:17
1

If I'm not understanding you correctly, please let me know. It seems that you want to know if a VNet has gateway connected when you have enabled VNet peering.

You could use Azure PowerShell (Get-AzVirtualNetwork -ResourceGroupName $myrg -Name $myVnet).VirtualNetworkPeerings, then you will check the value of parameter AllowGatewayTransit and UseRemoteGateways. One of those values is true, this vNet has a connecting gateway.

Additionally, the new Az module is used for Azure Resource Manager model, it's recommended to migrate Azure PowerShell from AzureRM to Az. If you still use the old AzureRM module, you could replace Get-AzVirtualNetwork with Get-azurermVirtualNetwork.

enter image description here

Nancy
  • 26,865
  • 3
  • 18
  • 34