I have not blogged in a long time, I really ought to rectify that. Today I got asked a question and thought I would blog the answer.

Can you change the virtual network/subnet that is being used by an Application Gateway?

From what I was aware you couldn’t do this from the console, and after a quick look you still cannot, so I had a look to see what I could do with PowerShell. This is what I came up with

 

Connect to Azure with an authenticated account

Connect-AzAccount

 You need to know the Subnet ID of the subnet you want to change to

(Get-AzVirtualNetwork).subnets | where-object  {$_.Name -match <subnet> } | select Name, Id

Retrieve and store the application gateway config

$GateWay=Get-AzApplicationGateway -Name <ApplicationGatewayName> -ResourceGroupName <ResourceGroupName>

 

Store the new config

$GateWayChange=Set-AzApplicationGatewayIPConfiguration -SubnetId <Id From Earlier> -ApplicationGateway $GateWay -Name $GateWay.GatewayIPConfigurations.Name

 

This change cannot be made whilst the Application Gateway is running

Stop-AzApplicationGateway -ApplicationGateway $GateWay

Apply the new config

Set-AzApplicationGateway -ApplicationGateway $GateWayChange

 

Now wait, be patient, it takes a while. In fact anything you do with the Application Gateway either via PowerShell or the console takes a while.

Anonymous