使用powershell New-AzResources创建应用程序网关探针、后端池、规则等

ztmd8pv5  于 2023-02-19  发布在  Shell
关注(0)|答案(1)|浏览(134)

我尝试使用powershell和命令new-AzResources在应用程序网关中创建一些对象,如探针、规则等。我使用以下代码片段:

### 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

但我得到以下错误:

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

我用同样的逻辑来创建应用服务,但是我不明白我在应用网关上做错了什么。你能给予我一个建议吗?
谢谢

c0vxltue

c0vxltue1#

我在我的环境中进行了复制,并从Microsoft-Document中获取了以下命令:
您提供的命令或脚本出现错误,因此,我已使用以下脚本创建应用程序网关。
首先,我使用以下命令创建了Subnet,然后创建了Vnet和所有其他所需资源:

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

输出:

在powershell中运行上述命令后,将在Portal中创建资源

相关问题