How to Create User-Defined Routes in Azure with PowerShell

After provisioning my RouteToSubnetB route, I provisioned a Route Table that I called SubnetA-SubnetB by running the command below:

$routeTable = New-AzureRmRouteTable -ResourceGroupName MyResourceGroup -Location westus -Name SubnetA-SubnetB -Route $route

The command above took the result of the New-AzureRMRouteTable command and stored it in a variable called $routeTable.  I’ve broken down the structure of the command below:

  • -ResourceGroupName: The name of the Azure resource group where I wanted to store the Route Table
  • -Location: The Azure Region where I wanted my resource deployed to
  • -Name: The name of the Route Table I was deploying
  • -Route: The value of the $route variable from the previous command

Assigning My New Resources

Once I had my RouteToSubnetB route defined and my SubnetA-SubnetB Route Table provisioned, I ran the following Get-AzureRmVirtualNetwork PowerShell command to pull my virtual network information into a variable called $vnet:

$vnet = Get-AzureRmVirtualNetwork -ResourceGroupName MyResourceGroup -Name VNetwork

The command above breaks down as follows:

  • -ResourceGroupName:  The name of my provisioned Resource Group
  • -Name:  The name of my virtual network

I then associated my new Route Table with the SubnetA subnet with the following command:

Set-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name SubnetA -AddressPrefix -RouteTable $routeTable

The syntax of the above command is as follows:

  • -VirtualNetwork:  The value of the $vnet variable from the prior command
  • -Name:  The name of the subnet I was associating the Route Table to
  • -AddressPrefix:  The address prefix of the SubnetA subnet
  • -RouteTable:  The Route Table I provisioned earlier in the process

Saving the Configuration for SubnetA Stuff

Click here to join the Understanding Azure Facebook group or here for the latest Azure practice questions, answers, explanations, and reference materials.

Thomas Mitchell

Tom is a 20+ year veteran of the IT industry and carries numerous Microsoft certifications, including the MCSE: Cloud Platform and Infrastructure certification. A Subject Matter Expert in Active Directory and Microsoft Exchange, Tom also possesses expert-level knowledge in several other IT disciplines, including Azure, Storage, and O365/Exchange Online. You can find Tom at his website, on LinkedIn, or on Facebook. Need to reach him by phone? Call 484-334-2790.