1 minutes to read

As I was testing with a Virtual Appliance that handles the traffic in my Azure VNET, I needed to create some User-Defined Routing. My deployment is done in Azure Resource Manager, so I was searching for a way to set User-Defined Routing with Azure Resource Manager and PowerShell. Most of the scripts I found where based on Azure Service Manager.

So I would like to share the Powershell (1.0) script with you.



$VMname = [name of your Virtual Appliance]
$ResourceGroup = [ResourceGroup]
$Location = [Location]
$NameRouteTable = [NameRoutingTable]
$NameRoute = [NameRoute]
$NextHopIP = [IP of your Virtual Appliance]
$VNET = [Your VNET]
$VNETid = Get-AzureRmVirtualNetwork -Name $VNET -ResourceGroupName $ResourceGroup
$Subnet = [Your Subnet]
$SubnetAddressPrefix = [Your Subnet Prefix]
$routeTable = Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable

$nicConfig = Get-AzureRmNetworkInterface -ResourceGroupName $ResourceGroup -Name $VMname
$nicConfig.EnableIPForwarding = $true
$nicConfig | Set-AzureRmNetworkInterface

New-AzureRmRouteTable -Name $NameRoutingTable -ResourceGroupName $ResourceGroup -Location $Location
New-AzureRmRouteConfig -Name $NameRoute -AddressPrefix -NextHopType VirtualAppliance -NextHopIpAddress $NextHopIP

Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable | $routeTable = Add-AzureRmRouteConfig -Name $NameRoute -AddressPrefix -NextHopType VirtualAppliance -NextHopIpAddress $NextHopIP | Set-AzureRmRouteTable
#Verify if everything is set correctly
Get-AzureRmRouteTable -ResourceGroupName $ResourceGroup -Name $NameRouteTable

Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $VNETid -Name $Subnet| Set-AzureRmVirtualNetworkSubnetConfig -AddressPrefix $SubnetAddressPrefix -Name $Subnet -VirtualNetwork $vnet -RouteTable $routeTable

User Defined Routing in Azure User Defined Routing in Azure