Powershell Script to configure Azure Application Gateway
# Variables
$resourceGroupName = "myResourceGroup"
$appGwName = "myAppGw"
$vnetName = "myVnet"
$subnetName = "mySubnet"
$frontendIpName = "myFrontendIp"
$frontendPortName = "myFrontendPort"
$backendPoolName = "myBackendPool"
$httpSettingsName = "myHttpSettings"
$httpListenerName = "myHttpListener"
$certName = "myCert"
# Connect to Azure
Connect-AzAccount
# Get the Application Gateway
$appGw = Get-AzApplicationGateway -ResourceGroupName $resourceGroupName -Name $appGwName
# Get the Virtual Network and Subnet
$vnet = Get-AzVirtualNetwork -ResourceGroupName $resourceGroupName -Name $vnetName
$subnet = Get-AzVirtualNetworkSubnetConfig -Name $subnetName -VirtualNetwork $vnet
# Configure the Frontend IP Configuration
$frontendIp = New-AzApplicationGatewayFrontendIPConfig -Name $frontendIpName -PrivateIPAddressVersion IPv4 -Subnet $subnet
$appGw | Add-AzApplicationGatewayFrontendIPConfig -FrontendIPConfiguration $frontendIp
# Configure the Frontend Port
$frontendPort = New-AzApplicationGatewayFrontendPort -Name $frontendPortName -Port 80
$appGw | Add-AzApplicationGatewayFrontendPort -FrontendPort $frontendPort
# Configure the Backend Pool
$backendPool = New-AzApplicationGatewayBackendAddressPool -Name $backendPoolName
$appGw | Add-AzApplicationGatewayBackendAddressPool -BackendAddressPool $backendPool
# Configure the HTTP Settings
$httpSettings = New-AzApplicationGatewayBackendHttpSettings -Name $httpSettingsName -Port 80 -Protocol Http -CookieBasedAffinity Enabled
$appGw | Add-AzApplicationGatewayBackendHttpSettings -BackendHttpSettings $httpSettings
# Configure the HTTP Listener
$httpListener = New-AzApplicationGatewayHttpListener -Name $httpListenerName -FrontendIPConfiguration $frontendIp -FrontendPort $frontendPort -Protocol Http
$appGw | Add-AzApplicationGatewayHttpListener -HttpListener $httpListener
# Configure the SSL Certificate
$cert = Get-AzApplicationGatewaySslCertificate -Name $certName -ApplicationGateway $appGw
$appGw | Set-AzApplicationGatewaySslCertificate -Name $certName -Certificate $cert.Certificate -Password $cert.Password
# Update the Application Gateway
Set-AzApplicationGateway -ApplicationGateway $appGw
Comments
Post a Comment