How To Create An Azure Virtual Network Gateway Using PowerShell

Introduction

If we have an existing Virtual Network Gateway for VPN, and when we are trying to create an additional Gateway for ExpressRoute, we will get an error called “in use,” so we can not create another Virtual Network Gateway in the Azure portal. In this article, we will learn how to resolve this issue using Azure PowerShell.

Why are we getting this kind of error?

If our Gateway Subnet address space is like /28, we will get this kind of error.

Step 1

In the Article Resource Group currently, we have a Virtual Network Gateway for VPN, now we will create an additional Virtual Network Gateway for ExpressRoute, so click Create.

How To Create An Azure Virtual Network Gateway Using PowerShell

Step 2

In the Create Virtual Network Gateway page, we have to select the below details

  • Subscription
  • Region – Select our Resource group region
  • Gateway type - ExpressRoute
  • Gateway SKU – Standard
  • Virtual Network – Select an existing Network

Now we got the error.

How To Create An Azure Virtual Network Gateway Using PowerShell

Step 3

Download this script and modify it as your requirement.

How To Create An Azure Virtual Network Gateway Using PowerShell

  • Connect-AzAccount – to connect the Azure account
  • Select-AzSubscription "Enter your Subscription Name"
  • $RG = "Resource group name"
  • $Location = "Resource group location"
  • $GWName = "Virtual Network Gateway name"
  • $GWIPName = "Virtual Network Gateway Public IP address name"
  • $GWIPconfName = "Virtual Network Gateway IP configure name"
  • $VNetName = "Virtual Network name"
  • $gwsubprefix = "GatewaySubnet address”

Step 4

Open the PowerShell ISE and run the script.

How To Create An Azure Virtual Network Gateway Using PowerShell

Step 5

The additional Virtual network gateway is created under the Resource group.

How To Create An Azure Virtual Network Gateway Using PowerShell


IFS R&D International (Private) Limited
IFS is a global enterprise software vendor providing solutions that help companies get better return