Provide an application gateway with PowerShell in Azure with a virtual machine scale set in the back

%3CLINGO-SUB%20id%3D%22lingo-sub-2005077%22%20slang%3D%22en-US%22%3EProvide%20an%20application%20gateway%20with%20PowerShell%20in%20Azure%20with%20a%20virtual%20machine%20scale%20set%20in%20the%20back%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2005077%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Azure%20friends%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20used%20the%20PowerShell%20ISE%20for%20this%20configuration.%20But%20you%20are%20also%20very%20welcome%20to%20use%20Visual%20Studio%20Code%2C%20just%20as%20you%20wish.%26nbsp%3BPlease%20start%20with%20the%20following%20steps%20to%20begin%20the%20deployment%20(the%20Hashtags%20are%20comments)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23The%20first%20two%20lines%20have%20nothing%20to%20do%20with%20the%20configuration%2C%20but%20make%20some%20space%20below%20in%20the%20blue%20part%20of%20the%20ISE%3C%2FP%3E%3CP%3E%3CSTRONG%3ESet-Location%20C%3A%5CTemp%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EClear-Host%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23So%20that%20you%20can%20carry%20out%20the%20configuration%2C%20you%20need%20the%20necessary%20cmdlets%2C%20these%20are%20contained%20in%20the%20module%20Az%20(is%20the%20higher-level%20module%20from%20a%20number%20of%20submodules)%3C%2FP%3E%3CP%3E%3CSTRONG%3EInstall-Module%20-Name%20Az%20-Force%20-AllowClobber%20-Verbose%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%23For%20this%20example%20I%20am%20using%20passwords%20in%20the%20script.%20This%20is%20usually%20not%20a%20good%20idea%2C%20but%20it's%20fine%20for%20the%20demo.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23Log%26nbsp%3Binto%26nbsp%3BAzure%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EConnect-AzAccount%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23Select%26nbsp%3Bthe%26nbsp%3Bcorrect%26nbsp%3Bsubscription%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzSubscription%26nbsp%3B-SubscriptionName%26nbsp%3B%22MSDN%26nbsp%3BPlatforms%22%26nbsp%3B%7C%26nbsp%3BSelect-AzSubscription%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzContext%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Ba%26nbsp%3Bresource%26nbsp%3Bgroup%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3ENew-AzResourceGroup%26nbsp%3B-Name%26nbsp%3BmyResourceGroupAG%26nbsp%3B-Location%26nbsp%3Bwesteurope%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Bnetwork%26nbsp%3Bresources%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24backendSubnetConfig%26nbsp%3B%3D%26nbsp%3BNew-AzVirtualNetworkSubnetConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyBackendSubnet%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AddressPrefix%26nbsp%3B10.0.1.0%2F24%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%24agSubnetConfig%26nbsp%3B%3D%26nbsp%3BNew-AzVirtualNetworkSubnetConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAGSubnet%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AddressPrefix%26nbsp%3B10.0.2.0%2F24%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%24vnet%26nbsp%3B%3D%26nbsp%3BNew-AzVirtualNetwork%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Location%26nbsp%3Bwesteurope%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyVNet%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AddressPrefix%26nbsp%3B10.0.0.0%2F16%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Subnet%26nbsp%3B%24backendSubnetConfig%2C%26nbsp%3B%24agSubnetConfig%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%24pip%26nbsp%3B%3D%26nbsp%3BNew-AzPublicIpAddress%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Location%26nbsp%3Bwesteurope%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAGPublicIPAddress%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AllocationMethod%26nbsp%3BDynamic%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3BIP%26nbsp%3Bconfigurations%26nbsp%3Band%26nbsp%3Bfrontend%26nbsp%3Bport%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24vnet%26nbsp%3B%3D%26nbsp%3BGet-AzVirtualNetwork%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyVNet%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24subnet%3D%24vnet.Subnets%5B0%5D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24gipconfig%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayIPConfiguration%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAGIPConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Subnet%26nbsp%3B%24subnet%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24fipconfig%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayFrontendIPConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAGFrontendIPConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-PublicIPAddress%26nbsp%3B%24pip%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24frontendport%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayFrontendPort%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyFrontendPort%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Port%26nbsp%3B80%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Bthe%26nbsp%3Bbackend%26nbsp%3Bpool%26nbsp%3Band%26nbsp%3Bsettings%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24defaultPool%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayBackendAddressPool%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BappGatewayBackendPool%26nbsp%3B%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%24poolSettings%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayBackendHttpSettings%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyPoolSettings%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Port%26nbsp%3B80%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Protocol%26nbsp%3BHttp%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-CookieBasedAffinity%26nbsp%3BEnabled%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-RequestTimeout%26nbsp%3B120%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Bthe%26nbsp%3Bdefault%26nbsp%3Blistener%26nbsp%3Band%26nbsp%3Brule%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24defaultlistener%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayHttpListener%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmydefaultListener%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Protocol%26nbsp%3BHttp%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-FrontendIPConfiguration%26nbsp%3B%24fipconfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-FrontendPort%26nbsp%3B%24frontendport%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24frontendRule%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewayRequestRoutingRule%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3Brule1%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-RuleType%26nbsp%3BBasic%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-HttpListener%26nbsp%3B%24defaultlistener%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-BackendAddressPool%26nbsp%3B%24defaultPool%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-BackendHttpSettings%26nbsp%3B%24poolSettings%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Bthe%26nbsp%3Bapplication%26nbsp%3Bgateway%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24sku%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGatewaySku%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BWAF_Medium%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Tier%26nbsp%3BWAF%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Capacity%26nbsp%3B2%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24appgw%26nbsp%3B%3D%26nbsp%3BNew-AzApplicationGateway%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAppGateway%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Location%26nbsp%3Bwesteurope%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-BackendAddressPools%26nbsp%3B%24defaultPool%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-BackendHttpSettingsCollection%26nbsp%3B%24poolSettings%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-FrontendIpConfigurations%26nbsp%3B%24fipconfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-GatewayIpConfigurations%26nbsp%3B%24gipconfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-FrontendPorts%26nbsp%3B%24frontendport%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-HttpListeners%26nbsp%3B%24defaultlistener%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-RequestRoutingRules%26nbsp%3B%24frontendRule%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Sku%26nbsp%3B%24sku%26nbsp%3B%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BCreate%26nbsp%3Ba%26nbsp%3Bvirtual%26nbsp%3Bmachine%26nbsp%3Bscale%26nbsp%3Bset%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24vnet%26nbsp%3B%3D%26nbsp%3BGet-AzVirtualNetwork%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyVNet%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24appgw%26nbsp%3B%3D%26nbsp%3BGet-AzApplicationGateway%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyAppGateway%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24backendPool%26nbsp%3B%3D%26nbsp%3BGet-AzApplicationGatewayBackendAddressPool%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BappGatewayBackendPool%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ApplicationGateway%26nbsp%3B%24appgw%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24ipConfig%26nbsp%3B%3D%26nbsp%3BNew-AzVmssIpConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyVmssIPConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-SubnetId%26nbsp%3B%24vnet.Subnets%5B1%5D.Id%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ApplicationGatewayBackendAddressPoolsId%26nbsp%3B%24backendPool.Id%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24vmssConfig%26nbsp%3B%3D%26nbsp%3BNew-AzVmssConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Location%26nbsp%3Bwesteurope%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-SkuCapacity%26nbsp%3B2%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-SkuName%26nbsp%3BStandard_DS2%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-UpgradePolicyMode%26nbsp%3BAutomatic%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3ESet-AzVmssStorageProfile%26nbsp%3B%24vmssConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ImageReferencePublisher%26nbsp%3BMicrosoftWindowsServer%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ImageReferenceOffer%26nbsp%3BWindowsServer%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ImageReferenceSku%26nbsp%3B2016-Datacenter%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ImageReferenceVersion%26nbsp%3Blatest%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-OsDiskCreateOption%26nbsp%3BFromImage%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3ESet-AzVmssOsProfile%26nbsp%3B%24vmssConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AdminUsername%26nbsp%3Bazureuser%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-AdminPassword%26nbsp%3B%22Azure123456!%22%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ComputerNamePrefix%26nbsp%3Bmyvmss%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3EAdd-AzVmssNetworkInterfaceConfiguration%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-VirtualMachineScaleSet%26nbsp%3B%24vmssConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3BmyVmssNetConfig%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Primary%26nbsp%3B%24true%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-IPConfiguration%26nbsp%3B%24ipConfig%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3ENew-AzVmss%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3Bmyvmss%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-VirtualMachineScaleSet%26nbsp%3B%24vmssConfig%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BInstall%26nbsp%3BIIS%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%24publicSettings%26nbsp%3B%3D%26nbsp%3B%40%7B%26nbsp%3B%22fileUris%22%26nbsp%3B%3D%26nbsp%3B(%2C%22%3CA%20href%3D%22https%3A%2F%2Fraw.githubusercontent.com%2Fdavidmu1%2Fsamplescripts%2Fmaster%2Fappgatewayurl.ps1%26quot%3B)%3B%26nbsp%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fraw.githubusercontent.com%2Fdavidmu1%2Fsamplescripts%2Fmaster%2Fappgatewayurl.ps1%22)%3B%26nbsp%3B%3C%2FA%3E%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B%22commandToExecute%22%26nbsp%3B%3D%26nbsp%3B%22powershell%26nbsp%3B-ExecutionPolicy%26nbsp%3BUnrestricted%26nbsp%3B-File%26nbsp%3Bappgatewayurl.ps1%22%26nbsp%3B%7D%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3E%24vmss%26nbsp%3B%3D%26nbsp%3BGet-AzVmss%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B-VMScaleSetName%26nbsp%3Bmyvmss%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3EAdd-AzVmssExtension%26nbsp%3B-VirtualMachineScaleSet%26nbsp%3B%24vmss%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3B%22customScript%22%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Publisher%26nbsp%3B%22Microsoft.Compute%22%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Type%26nbsp%3B%22CustomScriptExtension%22%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-TypeHandlerVersion%26nbsp%3B1.8%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Setting%26nbsp%3B%24publicSettings%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSTRONG%3EUpdate-AzVmss%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-Name%26nbsp%3Bmyvmss%26nbsp%3B%60%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3E%26nbsp%3B%26nbsp%3B-VirtualMachineScaleSet%26nbsp%3B%24vmss%3C%2FSTRONG%3E%3C%2FDIV%3E%3CBR%20%2F%3E%3CDIV%3E%3CSPAN%3E%23%26nbsp%3BGet%26nbsp%3Bthe%26nbsp%3BIP%26nbsp%3Baddress%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CSTRONG%3EGet-AzPublicIPAddress%26nbsp%3B-ResourceGroupName%26nbsp%3BmyResourceGroupAG%26nbsp%3B-Name%26nbsp%3BmyAGPublicIPAddress%3C%2FSTRONG%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3EStart%20the%20browser%20and%20paste%20the%20IP%20address.%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CSPAN%3ENow%20you%20have%20used%20the%20PowerShell%20to%20create%20Azure%20Application%20Gateway%20with%20a%20virtual%20machine%20scale%20set%20in%20the%20backend!%20Congratulations!%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CSPAN%3E%23Clean%26nbsp%3Bup%20(when%20you%20no%20longer%20need%20the%20resources)%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%3E%3CDIV%3E%3CDIV%3E%3CSTRONG%3ERemove-AzResourceGroup%26nbsp%3B-Name%26nbsp%3BmyResourceGroupAG%26nbsp%3B-Force%3C%2FSTRONG%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%3E%3CP%3EI%20hope%20this%20article%20was%20useful.%20Best%20regards%2C%20Tom%20Wechsler%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EP.S.%26nbsp%3BAll%20scripts%20(%23PowerShell%2C%20Azure%20CLI%2C%20%23Terraform%2C%20%23ARM)%20that%20I%20use%20can%20be%20found%20on%20github!%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Ftomwechsler%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Ftomwechsler%3C%2FA%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2005077%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EApplication%20Gateway%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVirtual%20Network%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Frequent Contributor

 

Hi Azure friends,

 

I used the PowerShell ISE for this configuration. But you are also very welcome to use Visual Studio Code, just as you wish. Please start with the following steps to begin the deployment (the Hashtags are comments):

 

#The first two lines have nothing to do with the configuration, but make some space below in the blue part of the ISE

Set-Location C:\Temp
Clear-Host

 

#So that you can carry out the configuration, you need the necessary cmdlets, these are contained in the module Az (is the higher-level module from a number of submodules)

Install-Module -Name Az -Force -AllowClobber -Verbose

 

#For this example I am using passwords in the script. This is usually not a good idea, but it's fine for the demo.

 

#Log into Azure
Connect-AzAccount

#Select the correct subscription
Get-AzSubscription -SubscriptionName "MSDN Platforms" | Select-AzSubscription
Get-AzContext

# Create a resource group
New-AzResourceGroup -Name myResourceGroupAG -Location westeurope

# Create network resources
$backendSubnetConfig = New-AzVirtualNetworkSubnetConfig `
  -Name myBackendSubnet `
  -AddressPrefix 10.0.1.0/24

  $agSubnetConfig = New-AzVirtualNetworkSubnetConfig `
  -Name myAGSubnet `
  -AddressPrefix 10.0.2.0/24

  $vnet = New-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Location westeurope `
  -Name myVNet `
  -AddressPrefix 10.0.0.0/16 `
  -Subnet $backendSubnetConfig, $agSubnetConfig

  $pip = New-AzPublicIpAddress `
  -ResourceGroupName myResourceGroupAG `
  -Location westeurope `
  -Name myAGPublicIPAddress `
  -AllocationMethod Dynamic

# Create IP configurations and frontend port
$vnet = Get-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Name myVNet

$subnet=$vnet.Subnets[0]

$gipconfig = New-AzApplicationGatewayIPConfiguration `
  -Name myAGIPConfig `
  -Subnet $subnet

$fipconfig = New-AzApplicationGatewayFrontendIPConfig `
  -Name myAGFrontendIPConfig `
  -PublicIPAddress $pip

$frontendport = New-AzApplicationGatewayFrontendPort `
  -Name myFrontendPort `
  -Port 80

# Create the backend pool and settings
$defaultPool = New-AzApplicationGatewayBackendAddressPool `
  -Name appGatewayBackendPool 

  $poolSettings = New-AzApplicationGatewayBackendHttpSettings `
  -Name myPoolSettings `
  -Port 80 `
  -Protocol Http `
  -CookieBasedAffinity Enabled `
  -RequestTimeout 120

# Create the default listener and rule
$defaultlistener = New-AzApplicationGatewayHttpListener `
  -Name mydefaultListener `
  -Protocol Http `
  -FrontendIPConfiguration $fipconfig `
  -FrontendPort $frontendport

$frontendRule = New-AzApplicationGatewayRequestRoutingRule `
  -Name rule1 `
  -RuleType Basic `
  -HttpListener $defaultlistener `
  -BackendAddressPool $defaultPool `
  -BackendHttpSettings $poolSettings

# Create the application gateway
$sku = New-AzApplicationGatewaySku `
  -Name WAF_Medium `
  -Tier WAF `
  -Capacity 2

$appgw = New-AzApplicationGateway `
  -Name myAppGateway `
  -ResourceGroupName myResourceGroupAG `
  -Location westeurope `
  -BackendAddressPools $defaultPool `
  -BackendHttpSettingsCollection $poolSettings `
  -FrontendIpConfigurations $fipconfig `
  -GatewayIpConfigurations $gipconfig `
  -FrontendPorts $frontendport `
  -HttpListeners $defaultlistener `
  -RequestRoutingRules $frontendRule `
  -Sku $sku 

# Create a virtual machine scale set
$vnet = Get-AzVirtualNetwork `
  -ResourceGroupName myResourceGroupAG `
  -Name myVNet

$appgw = Get-AzApplicationGateway `
  -ResourceGroupName myResourceGroupAG `
  -Name myAppGateway

$backendPool = Get-AzApplicationGatewayBackendAddressPool `
  -Name appGatewayBackendPool `
  -ApplicationGateway $appgw

$ipConfig = New-AzVmssIpConfig `
  -Name myVmssIPConfig `
  -SubnetId $vnet.Subnets[1].Id `
  -ApplicationGatewayBackendAddressPoolsId $backendPool.Id

$vmssConfig = New-AzVmssConfig `
  -Location westeurope `
  -SkuCapacity 2 `
  -SkuName Standard_DS2 `
  -UpgradePolicyMode Automatic

Set-AzVmssStorageProfile $vmssConfig `
  -ImageReferencePublisher MicrosoftWindowsServer `
  -ImageReferenceOffer WindowsServer `
  -ImageReferenceSku 2016-Datacenter `
  -ImageReferenceVersion latest
  -OsDiskCreateOption FromImage

Set-AzVmssOsProfile $vmssConfig `
  -AdminUsername azureuser `
  -AdminPassword "Azure123456!" `
  -ComputerNamePrefix myvmss

Add-AzVmssNetworkInterfaceConfiguration `
  -VirtualMachineScaleSet $vmssConfig `
  -Name myVmssNetConfig `
  -Primary $true `
  -IPConfiguration $ipConfig

New-AzVmss `
  -ResourceGroupName myResourceGroupAG `
  -Name myvmss `
  -VirtualMachineScaleSet $vmssConfig

# Install IIS
  "commandToExecute" = "powershell -ExecutionPolicy Unrestricted -File appgatewayurl.ps1" }

$vmss = Get-AzVmss -ResourceGroupName myResourceGroupAG -VMScaleSetName myvmss

Add-AzVmssExtension -VirtualMachineScaleSet $vmss `
  -Name "customScript" `
  -Publisher "Microsoft.Compute" `
  -Type "CustomScriptExtension" `
  -TypeHandlerVersion 1.8 `
  -Setting $publicSettings

Update-AzVmss `
  -ResourceGroupName myResourceGroupAG `
  -Name myvmss `
  -VirtualMachineScaleSet $vmss

# Get the IP address
Get-AzPublicIPAddress -ResourceGroupName myResourceGroupAG -Name myAGPublicIPAddress
 
Start the browser and paste the IP address.
 
Now you have used the PowerShell to create Azure Application Gateway with a virtual machine scale set in the backend! Congratulations!
 
#Clean up (when you no longer need the resources)
Remove-AzResourceGroup -Name myResourceGroupAG -Force
 

I hope this article was useful. Best regards, Tom Wechsler

 

P.S. All scripts (#PowerShell, Azure CLI, #Terraform, #ARM) that I use can be found on github! https://github.com/tomwechsler

 
0 Replies