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.
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.
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
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
.