Search code examples
powershellazure-powershellazure-application-gateway

Create Application Gateway probe, backend pool, rules ecc.. with powershell New-AzResources


i'm trying to create with powershell and and command new-AzResources some object, like probe, rules etc.. inside an application gateway. I'm using following snippet:

### Get properties
   $get = Get-AzResource -ResourceType Microsoft.Network/applicationGateways -Name appgw -ResourceGroupName rgappgw
$user.Properties.probes.Properties
     


$properties = @{
      protocol = 'Http';
      path = '/';
      interval = '30';
      timeout = '30';
      unhealthyThreshold = '3';
      pickHostNameFromBackendHttpSettings = $true;
      minServers = '0';
      match = '200-399';
    }
    
    
    $SlotParams = @{
      ResourceName = "appGwName"
      Location = "West Europe"
      ResourceGroupName = "AppGwRg"
      ResourceType = "Microsoft.Network/applicationGateways/probes/probename"   ####name of probes
      PropertyObject = $properties
    }
    
    $execution = New-AzResource @SlotParams -Force

but i'm getting following error:

New-AzResource: 
Line |
  23 |  $getSlotApse = New-AzResource @SlotParams -Force
     |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {
  "Message": "No HTTP resource was found that matches the request URI 'https://westeurope.network.azure.com:30058/123-124-14-4444-4444444/444444444444/subscriptions/mysubs/resourceGroups/AppGwRg/providers/Microsoft.Network/applicationGateways/appGwName/probes/probename?api-version=2022-07-01'."
}
CorrelationId: 12939812312831983

i use same logic to create app service but i'm not understand what i'm doing wrong with application gateway. Can you please give me an advice?

Thanks


Solution

  • I have reproduced in my environment and taken below commands from the Microsoft-Document:

    The command or script which you provided are giving errors for me so, I have used below script for creating application gateway.

    Firstly, I have created Subnet then Vnet and all the other required resources using below commands:

        Update-Module Az.Network  
            Connect-AzAccount  
            $subnet = New-AzVirtualNetworkSubnetConfig -Name subnet01 -AddressPrefix 10.0.0.0/24 -WarningAction Ignore  
            $vnet = New-AzVirtualNetwork -Name appgwvnet -ResourceGroupName "rithwik-resources" -Location 'East US' -AddressPrefix 10.0.0.0/16 -Subnet $subnet  
            $subnet = $vnet.Subnets[0]  
            $publicip = New-AzPublicIpAddress -ResourceGroupName "rithwik-resources" -Name publicIP01 -Location 'East US' -AllocationMethod Dynamic  
            $gipconfig = New-AzApplicationGatewayIPConfiguration -Name rithwikgatewayIP -Subnet $subnet -WarningAction Ignore  
            $pool = New-AzApplicationGatewayBackendAddressPool -Name pool01 -BackendIPAddresses 134.170.185.46, 134.170.188.221, 134.170.185.50 -WarningAction Ignore  
            $probe = New-AzApplicationGatewayProbeConfig -Name probe01 -Protocol Http -HostName 'test.com' -Path '/path/path.htm' -Interval 30 -Timeout 120 -UnhealthyThreshold 8 -WarningAction Ignore  
            $poolSetting = New-AzApplicationGatewayBackendHttpSettings -Name rithwikapps -Port 80 -Protocol Http -CookieBasedAffinity Disabled -Probe $probe -RequestTimeout 80 -WarningAction Ignore  
            $fp = New-AzApplicationGatewayFrontendPort -Name frontendport01 -Port 80 -WarningAction Ignore  
            $fipconfig = New-AzApplicationGatewayFrontendIPConfig -Name fipconfig01 -PublicIPAddress $publicip -WarningAction Ignore  
            $listener = New-AzApplicationGatewayHttpListener -Name listener01 -Protocol Http -FrontendIPConfiguration $fipconfig -FrontendPort $fp -WarningAction Ignore  
            $rule = New-AzApplicationGatewayRequestRoutingRule -Name rule01 -RuleType Basic -BackendHttpSettings $poolSetting -HttpListener $listener -BackendAddressPool $pool -WarningAction Ignore  
            $sku = New-AzApplicationGatewaySku -Name Standard_Small -Tier Standard -Capacity 2 -WarningAction Ignore  
            $appgw = New-AzApplicationGateway -Name appgwtest -ResourceGroupName "rithwik-resources" -Location 'East US' -BackendAddressPools $pool -Probes $probe -BackendHttpSettingsCollection $poolSetting -FrontendIpConfigurations $fipconfig -GatewayIpConfigurations $gipconfig -FrontendPorts $fp -HttpListeners $listener -RequestRoutingRules $rule -Sku $sku -WarningAction Ignore
    
    

    Output:

    enter image description here

    Once ran the above commands in powershell then the resources are created in Portal

    enter image description here